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 开发者_JAVA百科separate only those rows which have values 1, 2 3 or 4 in the 8th column. The file is space delimited.
You can use awk as:
awk '$8 == 1 || $8 == 2 || $8 == 3 || $8 == 4' file
Yet another AWK answer:
awk '$8 ~ /1|2|3|4/' inputfile
Use awk:
awk '$8 >= 1 && $8 <= 4' your_file.txt
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
精彩评论