Re: to remove leading and trailing blank lines

"Daniel" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>

Here is another way to remove leading and trailing blank lines:

--------------------------------
$ cat test.txt


non-blank 1
non-blank 2

non-blank 3


--------------------------------


--------------------------------
$ sed -n '/[^ ]/,$ p' test.txt | tac | sed -n '/[^ ]/,$ p' | tac
non-blank 1
non-blank 2

non-blank 3
--------------------------------

This assumes "blank line" means "line has some character other than blank".

Daniel

PS - Unfortunately, the yahoo groups web interface defaults to send the message to the previous poster, not to sed-users group. At least that's how it behaves when I use it. That's probably what happened.

--- In [email protected], Davide Brini <dave_br@...> wrote:
>
> On Mon, 01 Jul 2013 10:53:37 -0000, "contact2vikas"
> <contact2vikas@...> wrote:
> 
> > Thanks Dave,
> > Its working fine now. 
> > 
> > I am want to avoide creating sed file. Is it possible give me one or two
> > command from I can run from command line.
> 
> Please keep replies on the list. The command I used can be directly used on
> the command line, there's no need to create a file.
> 
> -- 
> D.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.