Mailinglist Archive: opensuse (2086 mails)

< Previous Next >
Re: [opensuse] How to insert lines into text file ?
  • From: Magnus Boman <captain.magnus@xxxxxxxxx>
  • Date: Thu, 16 Aug 2007 18:22:15 +1000
  • Message-id: <1187252535.25573.0.camel@xxxxxxxxxxxxxxxxxxxxx>
On Thu, 2007-08-16 at 10:15 +0200, Alexey Eremenko wrote:
> Hi all !
> 
> I would like to insert a new line on each second line, like that:
> 
> 
> pre.txt:
> line1
> line2
> line3
> 
> After.txt:
> line1
> 
> line2
> 
> line3
> 
> I have found the "echo -e "\n" " command to actually insert a new
> line, but how to automate the process so every second line will get a
> new line ?
> 
> please help

Quick and easy;
for i in `cat pre.txt`; do echo -e "$i\n"; done >after.txt

If that's all you want to do... If you do other sort of text
manipulation, have a look at sed.

Cheers,
Magnus


-- 
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References