帮助您使用awk选择行

时间:2009-11-21 01:32:48

标签: bash scripting awk

我有一个文件如下

  • 2.54 Ghz val
  • 2.53 Ghz val1
  • 1.6 Ghz val2
  • 800 Mhz val3
  • 2.54 Ghz val4
  • 2.53 Ghz val5
  • 1.6 Ghz val6
  • 800 Mhz val7

并且模式继续...... 我想在一个file1中提取所有2.54 Ghz值,在另一个file2中提取所有2.53 Ghz值 ,file3中的1.60 Ghz值和file4中的800 Mhz值

任何人都可以帮我这个吗?

2 个答案:

答案 0 :(得分:8)

 awk '{print $0 > "file_"$1"_"$2}' file

答案 1 :(得分:0)

Pure Bash:

rm --force file_*

while read speed magnitude value; do
    echo -e "${value}" >> "file_${speed}_${magnitude}"
done < file