List Info

Thread: Insert conditional newline if line 7 NEQ "B"




Insert conditional newline if line 7 NEQ "B"
country flaguser name
United States
2008-03-10 15:16:13
Kinda terse, yeah.. Here's what I hope you can help me
with.

I have a series of hundreds of small (10-15 line) text
files.

I need to check line 7.
If it does NOT begin with B, insert a newline.

If it does begin with B, don't do anything.

awk "NR==7 && substr($0,1,1)!="B"
{print""} " %1.b
was suggested (elsewhere) but that duplicates line 7 instead
of just
stuffing in a newline.

I've tried multiple variations on sed "7,1 s/" to
no avail.

Help me, Obi Wan-Kenobi, you're my only hope.


Thank you kindly.

Re: Insert conditional newline if line 7 NEQ "B"
country flaguser name
United States
2008-03-10 15:27:12
sed "7 s/^[^B].*/n&/"
did the trick, very nicely, thanks to a gent from Germany in
another
venue.


On Mar 10, 1:16 pm, John Bartley K7AAY <john.bart...gmail.com> wrote:
> Kinda terse, yeah.. Here's what I hope you can help me
with.
>
> I have a series of hundreds of small (10-15 line) text
files.
>
> I need to check line 7.
> If it does NOT begin with B, insert a newline.
>
> If it does begin with B, don't do anything.
>
> awk "NR==7 &&
substr($0,1,1)!="B" {print""} "
%1.b
> was suggested (elsewhere) but that duplicates line 7
instead of just
> stuffing in a newline.
>
> I've tried multiple variations on sed "7,1
s/" to no avail.
>
> Help me, Obi Wan-Kenobi, you're my only hope.
>
> Thank you kindly.


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )