Reputation: 13062
I have a huge file that I need to analyze. What I want to do is separate those rows that have certain values in a certain column. So, its like choosing only those data that belong to a certain category. How can this be accomplished with a simple bash commnand or script.
For example, I want to separate only those rows which have values 1, 2 3 or 4 in the 8th column. The file is space delimited.
Upvotes: 4
Views: 3479
Reputation: 360005
Yet another AWK answer:
awk '$8 ~ /1|2|3|4/' inputfile
Upvotes: 4
Reputation: 26086
Yet another awk answer.
awk '$8 ~ /[1-4]/' file
But, just for some variety, a bash answer
while read line ; do
fields=($line)
[[ ${fields[7]} =~ [1-4] ]] && echo $line
done < file
Upvotes: 2
Reputation: 454980
You can use awk as:
awk '$8 == 1 || $8 == 2 || $8 == 3 || $8 == 4' file
Upvotes: 4