ken6503
October 11, 2013, 12:30pm
1
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.
cjcox
October 11, 2013, 12:38pm
2
If using sed:
sed -e '/^START/d' -e '/^END/d' < inputfile > outputfile
1 Like
An awk Approach
$ awk '!/START/&&!/END/' inputfile >outputfile
ken6503
October 11, 2013, 12:53pm
4
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
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
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"
else
echo "I am here" echo
"let us see what in the file" `cat input`
echo "print this result" `egrep -v -e '^(END|START)' input`
" let see" #egrep -v -e '^(END|START)' input > input_tmp
echo "I am after you"
result:
I am here
let us see what in the file END # Result of "`cat input `" is printing here thats END
print this result let see I am after you
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
ken6503
October 11, 2013, 2:52pm
12
Thanks for your help to get me out from this stupid thing.
:o
It happens sometimes not to worry...