inserting a blank line after every line - using sed

inserting a blank line after every line - using sed

Post by dothe » Thu, 22 Aug 2002 21:19:08



Hi,
I want to change this file

aslfdkj
ldfjka
ldsjflas
sdlkfj
asdlfjk

to
aslfdkj

ldfjka

ldsjflas

sdlkfj

asdlfjk

How to do it using sed?
Tried using
sed 's/$/\n/' but it doesn't work
nor does
sed 's/$/\010/'
or
sed 's/$/'\010'/'

tia.
.^

 
 
 

inserting a blank line after every line - using sed

Post by Stephane Chazela » Thu, 22 Aug 2002 21:22:00




Quote:> I want to change this file

> aslfdkj
> ldfjka
> ldsjflas
> sdlkfj
> asdlfjk

> to
> aslfdkj

> ldfjka

> ldsjflas

> sdlkfj

> asdlfjk

> How to do it using sed?

sed G

Read the sed FAQ (http://www.faqs.org/faqs/editor-faq/sed/)

--
Stphane

 
 
 

inserting a blank line after every line - using sed

Post by Laurent Le Boterv » Thu, 22 Aug 2002 21:38:20


sed G file.txt



Quote:> Hi,
> I want to change this file

> aslfdkj
> ldfjka
> ldsjflas
> sdlkfj
> asdlfjk

> to
> aslfdkj

> ldfjka

> ldsjflas

> sdlkfj

> asdlfjk

> How to do it using sed?
> Tried using
> sed 's/$/\n/' but it doesn't work
> nor does
> sed 's/$/\010/'
> or
> sed 's/$/'\010'/'

> tia.
> .^

 
 
 

inserting a blank line after every line - using sed

Post by Bill Marcu » Fri, 23 Aug 2002 02:33:02


On 21 Aug 2002 05:19:08 -0700,

Quote:> Hi,
> I want to change this file
> aslfdkj
> ldfjka
> to
> aslfdkj

> ldfjka

> How to do it using sed?
> Tried using
> sed 's/$/\n/' but it doesn't work
> nor does
> sed 's/$/\010/'
> or
> sed 's/$/'\010'/'

sed 's/$/
/'

in csh:
sed 's/$/\\
'

 
 
 

inserting a blank line after every line - using sed

Post by Tho Nguy » Fri, 23 Aug 2002 10:43:29



> Hi,
> I want to change this file

> aslfdkj
> ldfjka
> ldsjflas
> sdlkfj
> asdlfjk

> to
> aslfdkj

> ldfjka

> ldsjflas

> sdlkfj

> asdlfjk

> How to do it using sed?
> Tried using
> sed 's/$/\n/' but it doesn't work
> nor does
> sed 's/$/\010/'
> or
> sed 's/$/'\010'/'

> tia.
> .^

How about
While read line
do
echo "$line";
echo;
done<yourfile
Please check the syntax.
 
 
 

inserting a blank line after every line - using sed

Post by singpg » Fri, 23 Aug 2002 18:27:07



> Hi,
> I want to change this file

> aslfdkj
> ldfjka
> ldsjflas
> sdlkfj
> asdlfjk

> to
> aslfdkj

> ldfjka

> ldsjflas

> sdlkfj

> asdlfjk

> How to do it using sed?
> Tried using
> sed 's/$/\n/' but it doesn't work
> nor does
> sed 's/$/\010/'
> or
> sed 's/$/'\010'/'

> tia.
> .^

#sed 'a\
 ' infile > outfile

or

#awk 'NR>1 {print " "} {print}' infile > outfile

HTH

 
 
 

inserting a blank line after every line - using sed

Post by Harm de Vrie » Sat, 24 Aug 2002 00:52:12




>> Hi,
>> I want to change this file

>> aslfdkj
>> ldfjka
>> ldsjflas
>> sdlkfj
>> asdlfjk

>> to
>> aslfdkj

>> ldfjka

>> ldsjflas

>> sdlkfj

>> asdlfjk

>> How to do it using sed?
>> Tried using
>> sed 's/$/\n/' but it doesn't work
>> nor does
>> sed 's/$/\010/'
>> or
>> sed 's/$/'\010'/'

>> tia.
>> .^
> #sed 'a\
>  ' infile > outfile
> or
> #awk 'NR>1 {print " "} {print}' infile > outfile
> HTH

Hmm there's a handy one-liner in the sed faq:

sed G infile > outfile

This will append a newline followed by the contents of the hold-space (by default empty)

--hdv

 
 
 

inserting a blank line after every line - using sed

Post by Harm de Vrie » Sat, 24 Aug 2002 01:05:46


Quote:> #sed 'a\
>  ' infile > outfile

I actually have to use:

sed 'a\
\
' infile > outfile

Quote:> or
> #awk 'NR>1 {print " "} {print}' infile > outfile

Wouldn't

awk '{ print; print "" }' infile > outfile

be better?

--hdv

Quote:> HTH

 
 
 

inserting a blank line after every line - using sed

Post by Charles Dem » Sat, 24 Aug 2002 09:20:55






>> Hi,
>> I want to change this file

>> aslfdkj
>> ldfjka
>> ldsjflas
>> sdlkfj
>> asdlfjk

>> to
>> aslfdkj

>> ldfjka

>> ldsjflas

>> sdlkfj

>> asdlfjk

>> How to do it using sed?
>> Tried using
>> sed 's/$/\n/' but it doesn't work
>> nor does
>> sed 's/$/\010/'
>> or
>> sed 's/$/'\010'/'

>> tia.
>> .^

>#sed 'a\
> ' infile > outfile

>or

>#awk 'NR>1 {print " "} {print}' infile > outfile

If you're going to use awk, this should be better:

awk '{print;print ""}' infile > outfile

or

awk '{printf("%s\n\n", $0}' infile > outfile

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

inserting a blank line after every line - using sed

Post by Sami Tikk » Tue, 27 Aug 2002 06:51:00



> While read line
> do
> echo "$line";
> echo;
> done<yourfile

I proposed a similar solution to another problem a couple of weeks back.
Stphane Chazelas pointed out the errors in that and suggested replacing
the 'read' statement with 'read -r'. 'Read' also has the side effect
that it will strip any leading and trailing whitespace. Granted, these
might not be showstoppers but it is good to be aware of the possible
problems lurking there.
 
 
 

inserting a blank line after every line - using sed

Post by Chris F.A. Johnso » Tue, 27 Aug 2002 07:41:07




>> While read line
>> do
>> echo "$line";
>> echo;
>> done<yourfile

> I proposed a similar solution to another problem a couple of weeks back.
> Stphane Chazelas pointed out the errors in that and suggested replacing
> the 'read' statement with 'read -r'. 'Read' also has the side effect
> that it will strip any leading and trailing whitespace. Granted, these
> might not be showstoppers but it is good to be aware of the possible
> problems lurking there.

   You can avoid stripping whitespace by:

       while IFS= read [-r] line

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2002, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

1. inserting lines before and after lines with matching pattern using sed?

I need to go through a file and wherever I find lines that contain a
certain string I need to insert a line above and below that line.
Lines that don't contain the string can go straight into the new file.

I've been trying various sed commands to no avail.  Can this be done
with sed, or am I wasting my time and need to go at it a different
way?  If it can be done with sed, how?

Thanks,
Rob Eger

Tech-X Corporation
Boulder, CO

2. Linux & Audio Visualizations?

3. Insert a line of text every nth line

4. Linux problems on AST PowerExec laptop

5. Vi -- How to Insert a Blank Line to all existing lines

6. Netscape front-end for end-users

7. insert a blank line to divide blocks of lines

8. Linux/Hurd vs GNU/Linux (was Re: Nvidia and its choice to read the GPL "differently")

9. sed/awk question : delete first blank in every line

10. Delete a whole line with sed, then insert diff text on same line...

11. vi: convert double blank lines to single blank lines???

12. How do I insert line numbers before each line using ed?

13. multiple blank lines -> one blank line