sed + cut words before the first “END” word in line
How to cut words before the first “END” word in line, and not include the first character before the “END” word ( in our examples the character is “-“)
Only with sed command
For example:
echo AAA-BBB-CCC-END | sed ...
AAA-BBB-CCC
echo 1-END-3-4 | sed ...
1
echo 1-2-END-3-4 | sed ...
1-2
echo PARAM1-PARAM2-END | sed ...
PARAM1-PARAM2
echo fileExample1-fileExample2-END | sed ...
fileExample1-fileE开发者_如何转开发xample2
echo xyz_123-END | sed ...
xyz_123
sed "s/.END.*//"
This should do the trick.
It'll remove the first char before the END, and all chars after (and of course the END itself).
sed -r "s/(.*).END.*/\1/"
would be my suggestion
if your string structure always have hyphens and then the "END" word (eg -END),
$ var="AAA-BBB-CCC-SEND-END"
$ echo ${var%%-END*}
AAA-BBB-CCC-SEND
As you can see, in case you have words like "SEND", it will still give you the correct output.
if you still prefer using sed,
$ echo $var | sed 's/-END.*//'
AAA-BBB-CCC-SEND
this seems to work: awkish not sedish, & literal
awk '$0 !~ /(echo*|^$)/'
精彩评论