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

John Bartley K7AAY <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization http://groups.google.com
Message-ID <[email protected]>
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 <[email protected]> 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.
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.