For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2005 > Simple query how do I print a space after every second line or after a certain matc









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple query how do I print a space after every second line or after a certain matc
sammy

2005-05-03, 3:56 am

Below works for each line but I would like every second line a space.

awk '{print;print ""}' filname

What I would like is below:

start of day
end of day

start of day
end of day

Also I'd like to use a search critera as an option also ie search for say
start and then print next two lines and have a space ie same
as above output but using search. Something like below that does not work.

awk '/start/ {print;print ""}'

Thanks in advance
Sammy




Loki Harfagr

2005-05-03, 3:56 pm

Le Tue, 03 May 2005 03:41:50 +0000, sammy a écrit_:

> Below works for each line but I would like every second line a space.
>
> awk '{print;print ""}' filname
>
> What I would like is below:
>
> start of day
> end of day
>
> start of day
> end of day
>
> Also I'd like to use a search critera as an option also ie search for say
> start and then print next two lines and have a space ie same
> as above output but using search. Something like below that does not work.
>
> awk '/start/ {print;print ""}'


Have a try starting whith this :
awk '{print};(NR%2==0) {print ""}'
sammy

2005-05-04, 3:56 am

Thanks for advice
Sammy
"Kenny McCormack" <gazelle@yin.interaccess.com> wrote in message
news:d58klg$1vs$1@yin.interaccess.com...
> In article <d58ig1$kot@netnews.proxy.lucent.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
> ...
>
> ORS=NR%2?"\n":"\n\n"



Loki Harfagr

2005-05-06, 3:55 pm

Le Tue, 03 May 2005 03:41:50 +0000, sammy a écrit_:

> Below works for each line but I would like every second line a space.
>
> awk '{print;print ""}' filname
>
> What I would like is below:
>
> start of day
> end of day
>
> start of day
> end of day
>
> Also I'd like to use a search critera as an option also ie search for say
> start and then print next two lines and have a space ie same
> as above output but using search. Something like below that does not work.
>
> awk '/start/ {print;print ""}'


Have a try starting whith this :
awk '{print};(NR%2==0) {print ""}'
sammy

2005-05-06, 3:56 pm

Thanks for advice
Sammy
"Kenny McCormack" <gazelle@yin.interaccess.com> wrote in message
news:d58klg$1vs$1@yin.interaccess.com...
> In article <d58ig1$kot@netnews.proxy.lucent.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
> ...
>
> ORS=NR%2?"\n":"\n\n"



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com