[英]bash scripting - print only specific rows in file
I have the following file (file.txt):我有以下文件(file.txt):
Ex1=-1.397311E+03 WEIGHT= 8.123000E-01
Ex2= 1.952565E+03 WEIGHT= 1.204200E+00
Ex3=-2.737476E+03 WEIGHT= 9.174491E-01
Ex4=-1.703835E+03 WEIGHT= 3.339300E-01
Ey1= 8.098997E+01 WEIGHT= 1.000000E+00
Ey2= 1.812711E+03 WEIGHT= 1.977300E+00
Ex5= 1.654618E+03 WEIGHT= 6.365700E-02
Ey3=-5.958670E+02 WEIGHT= 1.480850E+00
Ey4= 0.000000E+00 WEIGHT= 0.000000E+00
Ey5= 0.000000E+00 WEIGHT= 1.000000E+00
Ex6=-5.413463E+03 WEIGHT= 3.998912E-02
Ex7= 5.537537E+02 WEIGHT= 1.583826E+00
I want to print first and second column from rows beginning with Ex1, Ex2, Ex3, Ex4, Ex5, Ex6, Ex7.我想打印以 Ex1、Ex2、Ex3、Ex4、Ex5、Ex6、Ex7 开头的行的第一列和第二列。 I've tried to do this using sed command, but I have many problems in this area.
我尝试使用 sed 命令来做到这一点,但我在这方面有很多问题。 Could you help me?
你可以帮帮我吗?
It's not entirely clear what you mean by "column", but I suspect you want one of the following:尚不完全清楚您所说的“列”是什么意思,但我怀疑您想要以下之一:
$ awk '/Ex[1-7]/{print $1, $2}' FS='[= ]*' OFS== file.txt
Ex1=-1.397311E+03
Ex2=1.952565E+03
Ex3=-2.737476E+03
Ex4=-1.703835E+03
Ex5=1.654618E+03
Ex6=-5.413463E+03
Ex7=5.537537E+02
$ awk '/Ex[1-7]/{print $2, $4}' FS='[= ]*' file.txt
-1.397311E+03 8.123000E-01
1.952565E+03 1.204200E+00
-2.737476E+03 9.174491E-01
-1.703835E+03 3.339300E-01
1.654618E+03 6.365700E-02
-5.413463E+03 3.998912E-02
5.537537E+02 1.583826E+00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.