tags:

views:

38

answers:

4

Hi all

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-fileExample2


  echo xyz_123-END | sed ...
  xyz_123
+3  A: 
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).

Hendrik
A: 
sed -r "s/(.*).END.*/\1/"

would be my suggestion

martin
A: 

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
ghostdog74
A: 

this seems to work: awkish not sedish, & literal

awk '$0 !~ /(echo*|^$)/'

Ptarmigan