1828491 Members
2248 Online
109978 Solutions
New Discussion

Re: Sed

 
SOLVED
Go to solution
Vanquish
Occasional Advisor

Sed

I want to delete 1st 2 lines and 1st empty space and last empty space in a text file
in a script.

ABCDEFG
-------
AANHITW
ABEAWGI
ABEGIGI

i dont need 1st 2 lines and remove spaces before and after each line.
does
sed -e '/ /d' '1,2,$d' infile >> outfile


Thanks
4 REPLIES 4
Lee Hundley
Valued Contributor
Solution

Re: Sed

Try this...

sed -e '1,2d' infile | sed -e 's/^ *//' | sed -e 's/ *$//' > outfile

Probably a way to do it with fewer commands, but that worked for me.

The first part removes the first 2 lines, next remove all whitespace at the beginning of each line, then remove all whitespace at the end of each line. Hope that helps

infile:

ABCDEFG
-------
AANHITW
ABEAWGI (<- 2 whitespaces here)
ABEGIGI

outfile:

AANHITW
ABEAWGI
ABEGIGI


diff:

1,4c1,2
< ABCDEFG
< -------
< AANHITW
< ABEAWGI
---
> AANHITW
> ABEAWGI

It is my firm belief that it is a mistake to hold any firm beliefs
Steven E. Protter
Exalted Contributor

Re: Sed

Congrats to Lee on your first itrc linux points and your first bunny.

Keep on foruming.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Lee Hundley
Valued Contributor

Re: Sed

Beginner's luck I suppose. Is there anyway to markup text so its viewed as monospace, something like
 in html? I noticed the presence of the leading whitespace was almost indistinguisable.
It is my firm belief that it is a mistake to hold any firm beliefs
Stuart Browne
Honored Contributor

Re: Sed

Lee, unfortunately not at this time. It has been mentioned a few times, but no joy yet.

If you want, make your suggestion in the 'Forum Issues' thread over in the HPUX/General section. Thats the home for it!
One long-haired git at your service...