[Novalug] sed syntax question

James Ewing Cottrell 3rd JECottrell3@Comcast.NET
Mon Mar 12 02:23:12 EDT 2007


You violated on of Root Boy's Laws: Never Use AWK

Oh wait. You said SED. Well, don't use that either for anthing more 
complicated than "s/foo/bar".

You could use Perl, or, if I grok what you are Really Trying To Do, use 
either TR or FMT.

You could run your run your file thru "tr ' ' \\012", translating every 
space to a newline. And fmt will justify your text for you, inserting a 
newline where the rightmost space is before the 78th (I think) column.

And WTF is the CAT command doing there???? The shell has input 
redirection too ya know!

JIM

Megan Larko wrote:

> Hello,
>
> I have spent nearly two hours trying to solve what I think should be a 
> simple problem.
> I have a file (an auto-generated html file in my specific case) which 
> is only one line.
> One very, very looonng line.
>
> I would like to automatically parse it to extract a word.  Because the 
> file is a single line, I am trying to use the sed command to insert 
> (or substitute,  I'm not picky here) a newline or carriage return 
> character in an effort to break the single line up into smaller lines 
> for subsequent (g)awk -ing.
>
> I have tried many versions of:
>  cat ftp.html | sed i/bytes/bytes\n > meg
>  cat ftp2u.html | sed i/bytes/\n/ > meg
>
> The results are indeed in the "meg" output file---one line with 
> "/bytes/bytesn" or "/bytes" and a second line which is the entire 
> ftp.html one long-line file.
>
> I have tried:
>  cat ftp.html | sed s/bytes/bytes\n/ > meg
>
> The result is only the one long-line file; no newlines inserted 
> following the character string "bytes".
>
>
> I've been looking in O'Reillys "sed & awk"  2nd Edition but I'm not 
> finding what I need.  The index for "insert" (Chapter on insert pp 
> 87-90), "newline" and "return" have shown the special chars but not 
> enough of an example for me to get the syntax I would like to be correct.
>
> Any directions on where I should look for this?
>
> Thanks,
> megan
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/cgi-bin/mailman/listinfo/novalug
>
>




More information about the Novalug mailing list