ちゃんとカテゴリ分けされておりませんので、
記事をお探しならブログ内検索が便利です。
ご活用くださいませー+.(≧∀≦)゚+.゚
ブログ内検索
カレンダー
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 לפרטים נוספים]
最新記事
(02/19)
(01/16)
(12/29)
(12/28)
(12/28)
最新トラックバック
プロフィール
+ハンドル+
y_ayamori(purple)
+職業+
IT系エンジニア
+すまい+
さいたま
y_ayamori(purple)
+職業+
IT系エンジニア
+すまい+
さいたま
使い方をすぐに忘れてググるんだけど案外、求める答えがないので記録しておきますね。
〆目的
ファイル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]を複数使えば実現できます。
〆目的
ファイル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
この記事にコメントする
◆ 無題
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!!
“return the favor”.I'm attempting to find things to
improve my site!I suppose its ok to use some of your ideas!!
◆ 無題
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…
I definitely enjoyed every little bit of it. I have you book
marked to check out new things you post…
◆ 無題
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.
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.
◆ 無題
Aqui encontra slots, jackpots, exclusivos do Casino 888 Pt, com dezenas de jogos elegíveis.
Idealmente mude para o superusuário logo aqui.
Idealmente mude para o superusuário logo aqui.
◆ 無題
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…
bit of it. I have got you book marked to look at new things you post…