egrep -i '** pid|material|behavior=m' test.inc
这是命令 ( )的输出
输出是;
PID1:aaa1
MATERIAL1:sss1
PID2:aaa2
MATERIAL2:sss2
PID3:aaa3
MATERIAL3:sss3
CONNECTOR SECTION, ELIMINATION=NO, ELSET=P19933026;SPW_NF-19933026, BEHAVIOR=M19933000;xxxxxxxx_xxx
我希望输出必须是;
PID1:aaa1
MATERIAL1:sss1
PID2:aaa2
MATERIAL2:sss2
PID3:aaa3
MATERIAL3:sss3
BEHAVIOR=M19933000;xxxxxxxx_xxx
答案1
尝试这个 :
echo 'CONNECTOR SECTION, ELIMINATION=NO, ELSET=P19933026;SPW_NF-19933026, BEHAVIOR=M19933000;xxxxxxxx_xxx' |
grep -o 'BEHAVIOR=.*'
或者使用巴什:
grep -o 'BEHAVIOR=.*' <<< 'CONNECTOR SECTION, ELIMINATION=NO, ELSET=P19933026;SPW_NF-19933026, BEHAVIOR=M19933000;xxxxxxxx_xxx'
编辑 :
你不清楚,但如果我明白你想要什么:
egrep -i '** pid|material' | sed -r 's/.*(BEHAVIOR=.*)/\1/'
答案2
egrep -io '(pid|material|behavior=m).*' test.inc