忍者ブログ
Admin / Write / Res
ちゃんとカテゴリ分けされておりませんので、 記事をお探しならブログ内検索が便利です。 ご活用くださいませー+.(≧∀≦)゚+.゚
ブログ内検索
カレンダー
03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
カウンター
アクセスカウンター
最新コメント
[04/05 Fully Vaccinated Adorable Escort Service in bengaluru 8273600238]
[03/26 Tonaldcet]
[01/16 jilibet]
[10/20 Call Girl in Delhi]
[09/07 לפרטים נוספים]
最新トラックバック
プロフィール
+ハンドル+
y_ayamori(purple)
+職業+
IT系エンジニア
+すまい+
さいたま
バーコード
[632]  [631]  [630]  [629]  [628]  [627]  [626]  [624]  [623]  [622]  [621
使い方をすぐに忘れてググるんだけど案外、求める答えがないので記録しておきますね。

〆目的
ファイルBの中にファイルAに列記した文字列があるかどうかを確認し、あれば標準出力する
ファイルAは改行コードで区切られた文字列分探し出す。

〆ソースコード
------------------------------------------------------------
#!/bin/bash
file_a="./word.lst"
file_b="./text.txt"

while read line
do
    awk -v str=$line '{if ($0 == str){print $0}}'
done < ${file_a}
------------------------------------------------------------

[-v]がミソ。
awk構文(シングルクォート内)でシェル変数を展開するのではなく、
awk構文に入る前にawk変数を定義してしまえば、エスケープの嵐にあわなくてすみます。
複数のシェル変数を渡す場合は[-v]を複数使えば実現できます。


拍手

PR
この記事にコメントする
Name
Title
Color
Mail
URL
Comment
Password   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
secret (管理人にのみ表示)
◆ 無題
Yes! Finally someone writes about אתר ליווי.
Edgar URL 2023/03/21(Tue)21:19:21 編集
◆ 無題
Thanks for finally talking about >アナログを愛するデジタル生活館 【Linux】 シェル変数をawkに渡す <Liked it!
hongblogger.com URL 2023/04/24(Mon)20:37:13 編集
◆ 無題
Hi, i think that i saw you visited my site so i came to
“return the favor”.I'm attempting to find things to
improve my site!I suppose its ok to use some of your ideas!!
click for source URL 2023/05/06(Sat)21:01:13 編集
◆ 無題
I wanted to thank you for this excellent read!!
I definitely enjoyed every little bit of it. I have you book
marked to check out new things you post…
call girls in delhi URL 2023/06/28(Wed)16:50:38 編集
◆ 無題
Intressant inlägg, tack för att du delar!
hämta dödsbo stockholm URL 2023/08/04(Fri)17:00:47 編集
◆ 無題
Hmm іѕ anyone else experiencing problemѕ with
the images on this blog loading? I'm tгying to determine іf
itѕ a prоblem on my end or if it'ѕ tthe blog.
Any feedback ԝould bbe ցreatly appreciated.
on-page seo URL 2023/08/06(Sun)04:52:17 編集
◆ 無題
Aqui encontra slots, jackpots, exclusivos do Casino 888 Pt, com dezenas de jogos elegíveis.
Idealmente mude para o superusuário logo aqui.
nuevos casinos online 2022 URL 2023/08/14(Mon)13:54:58 編集
◆ 無題
סבין ערביה מדהימה מהדרום עכשיו במרכז.
לפרטים נוספים URL 2023/09/07(Thu)17:08:24 編集
◆ 無題
I needed to thank you for this good read!! I absolutely loved every little
bit of it. I have got you book marked to look at new things you post…
Call Girl in Delhi URL 2023/10/20(Fri)02:44:10 編集
◆ 無題
I’m not that much of a online reader to be honest but your blogs really nice, keep it
up! I'll go ahead and bookmark your website to come back later.

Many thanks
jilibet URL 2024/01/16(Tue)21:01:37 編集
◆ 無題
This is a really good tip particularly to those fresh
to the blogosphere. Brief but very accurate info… Thanks for sharing this one.
A must read post!
この記事へのトラックバック
この記事にトラックバックする:
Copyright ©  アナログを愛するデジタル生活館 All Rights Reserved.
* material by Pearl Box   * Template by tsukika

忍者ブログ [PR]