Operating System - HP-UX
1834394 Members
1540 Online
110066 Solutions
New Discussion

Re: sed to delete a line with fixed start

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

sed to delete a line with fixed start

Hi,

Got a lot of xml files that I need to delete a line out of before my browser opens them.
The line always starts with
but the rest will always be different.

How can I use sed to do a delete or ' ' replacement of the entire line based on this.

Thanks guys!
Bill
It works for me (tm)
9 REPLIES 9
John Poff
Honored Contributor
Solution

Re: sed to delete a line with fixed start

Hi Bill,

Try this:

sed '/^


JP
John Poff
Honored Contributor

Re: sed to delete a line with fixed start

Hi,

That last example works for being at the beginning of the line. If you want to delete the lines that contain anywhere on the line, just try it without the caret symbol:

sed '/


JP
Joseph C. Denman
Honored Contributor

Re: sed to delete a line with fixed start

Bill,

I think this will work.

sed '/^ filename.out
mv filename.out filename

...jcd...




If I had only read the instructions first??
Thierry Poels_1
Honored Contributor

Re: sed to delete a line with fixed start

hi,
how about "grep -v ..." ?
regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Bill McNAMARA_1
Honored Contributor

Re: sed to delete a line with fixed start

Thanks guys,
it was just a simple cut and paste,
you saved me a lot of time... (I can go home
early now!)
Thanks,
have a good weekend.

Later,
Bill
It works for me (tm)
Thierry Poels_1
Honored Contributor

Re: sed to delete a line with fixed start

grep -v '^ $F ;-)
regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Joseph C. Denman
Honored Contributor

Re: sed to delete a line with fixed start

Bill,

I really don't know what is happening. I cut and paste your script and your file. Ran your script and everything worked fine as expected??????????

If adding a line to the end fixes your problem, then add it. Before the sed's in your script do:

echo "" >> $F


...jcd...
If I had only read the instructions first??
Bill McNAMARA_1
Honored Contributor

Re: sed to delete a line with fixed start

yea, I'm baffled too.

after further analysis it appears to be only happening to files with encoding="UTF-8"
possibly related to the...
sed "s/$OLD/$NEW/g" $F > ${F}.tmp
I'll remove the rm just to verify and get back to you all.

Later,
Bill
It works for me (tm)
Bob_Vance
Esteemed Contributor

Re: sed to delete a line with fixed start

Yeah. Could be construed as a bug, I suppose.
'sed' will drop the last "line" of a file if it has not been terminated by a newline char (I guess that it's not really a "line", then, is it :).
'grep -v', as was suggested, doesn't suffer from this malady, however.
"The lyf so short, the craft so long to lerne." - Chaucer