したがって、次の行を含むテキストファイルがあります。
http://sg.ovies.m/.ss/ (Status: 200) [Size: 128]
http://sg.mo.v/.dev/ (Status: 200) [Size: 12328]
http://som.b/.hal/ (Status: 200) [Size: 1238]
http://m.cb/.ho/ (Status: 200) [Size: 0]
http://sm.jo/.hK/ (Status: 200) [Size: 0]`
サイズが1から100の間の行だけをgrepしたいと思います。
したがって、出力は次のようになります。
http://sg.ovies.m/.ss/ (Status: 200) [Size: 128]
http://sg.mo.v/.dev/ (Status: 200) [Size: 12328]
http://som.b/.hal/ (Status: 200) [Size: 1238]
grep または awk を使ってこれを行うにはどうすればよいですか?
ベストアンサー1
Awkを使用すると、次の作業が簡単になります。
awk '{size=$5; sub(/]/, "", size); size=size+0; if (size <= 100 && size >= 1) {print $0 } }' file_to_read.txt
以下をもっと親しみやすいものにしてください。
awk '{
# create a new variable "size".
# items are separated by spaces, we need the 5th item
size=$5;
# remove the trailing "]"
sub(/]/, "", size);
# make sure size is an int
size=size+0;
# Choose rows with seize between 1 and 100
if (size <= 100 && size >= 1) {
# print the whole line
print
}
}' file_to_read.txt