How to delete either of one line from file.?

Hi gurus,

I have one file it may contains one line is "START" or "FINISH" either one of them.
I use below command to delete it, but it doens't work.

sed '/^START\|^END/d' <inputfile > outfile
 

anybody can help me to fix this.

thanks in advance.

If using sed:

sed -e '/^START/d' -e '/^END/d' < inputfile > outputfile
1 Like

An awk Approach

$ awk '!/START/&&!/END/'  inputfile >outputfile

Thanks for your quick replay,
I got another issue.
I tried it in command line, it works
but if I put in script, it doesn't work.
below is the portition, it print out "here", but doesn't delete the line

else
echo "here"
sed -e '/^ALL/d' -e '/^FILE/d' < file> file_tmp
#mv file_tmp file

Thanks again.

You can also use grep

grep -v -E '^(END|START)'  infile >outfile
1 Like

when using below command
i got error.

grep -v -E '^(END|START)' infile
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

My OS is
SunOS 5.10 Generic_144488-17 sun4v sparc SUNW,SPARC-Enterprise-

any idea?

Thanks

See

$ cat abc 
START

HAI 
HEKKO
FOO
FOOA
END
FOO
NNO
$ grep -v -E '^(END|START)' abc 

HAI 
HEKKO
FOO
FOOA
FOO
NNO

try with egrep or with small e

1 Like

I got something unusual:
I tried the command it works, but after put in script, it doesn't work.

 else
           echo "I am here"
           echo "print this result" `egrep -v -e '^(END|START)' input` " let see"
           echo "I am after you"
           #egrep -v -e '^(END|START)
           #sed -e '/^ALL/d' -e '/^FILE/d' < input > input_tmp

I got below result:

I am here
print this result  let see
I am after you

any idea about this?

Thanks

can you post your input file ?

try without Grave accents

$echo "print this result" $(egrep -v -e '^(END|START)' file) " let see"

You are telling script that not to print line with END or START so you are getting only
print this result let see

1 Like

Thanks for your help to get me out from this stupid thing.
:o :smiley:
:b:

It happens sometimes not to worry...