[Novalug] sed syntax question

C Megan Larko larkoc@cola.iges.org
Fri Mar 9 22:29:41 EST 2007


Hello Don,

On Fri, Mar 09, 2007 at 06:57:34PM -0500, Groves Don wrote:
> Megan,
>    You are still doing the same BAD/sloppy MISTAKE of not properly
> quoting your parameters. While most of the time you can get by with not
> fully quoting parameters when working a the command-line it is almost
> never safe within scripts.

True.  I have always had difficulties getting commands I can run 
at my shell prompt to work properly in a script.  It has been a thorn in 
my side for years.  It's not any easier when I am asked to "do this in 
an hour".  (plus a major system crash today.  I am so--- glad it's 
Friday.)
> 
>   If you are going to use the exec
>   the line instead of:
>     exec "tr ' ' \\n < ftp2u.html > temp.out";
> 
>  should be something like:
>     exec "tr ' ' '\n' < ftp2u.html > temp.out";
> 
>  Notice how I delimited each parameter with quotes.

I had thought that I could not use the same type of quotes more
than once in a line for some reason.
> 
> 
> And instead of the Perl at all, why not try this one liner:
> 
>   sed 's/<br>/\n/g' < ftp2u.html | grep 'bytes' 
> 
> Which splits the file on the html line breaks.
>  {see <BR> defined <http://www.htmlcodetutorial.com/linepar/_BR.html>}
> and the filters out the junk with grep.
> 
> And to report how many bytes total completed, how about:
> 
>  sed 's/<br>/\n/g' < ftp2u.html |\
>   awk '
>     /, [0-9]+ bytes/
>     {
>       split($0,ar,", [0-9]+ bytes");         # find the piece I want
>       split(substr($0,length(ar[1])+3),op);  # store the NUMBER only in op[1]
>       tot+=op[1];                            # total them up.
>      }
>     END
>     {
>       print tot;          #  at the end of input, output the total.
>     }
>    '
> 
> Minus the comments it will work on one long line.
> 
> sed 's/<br>/\n/g' < ftp2u.html | awk '/, [0-9]+ bytes/{split($0,ar,", [0-9]+ bytes");split(substr($0,length(ar[1])+3),op);tot+=op[1];}END{print tot;}'
> 
> Note it most likely got split funny this time, as it's 152 characters long.
> 
After I posted my quick attempt, the user said that he preferred it to
be in csh or tcsh because he didn't think that a perl interpreter 
would be available everywhere the code might run.

I had thought he was running a test case to see how much new data might
be available a day from this one site, not that he wanted a more 
permanent solution.  Hey, I'm just a sysadmin, not a science project
planner.

Thank you again for the suggestion.  I'm trying over the w-e to 
do the same task in tcsh.  I look forward to trying you suggestion 
Saturday.

Enjoy your weekend!
megan 
> --  
> -- 
>  Don E. Groves, Jr. 
> 
> $ /usr/games/fortune : Are you sure the back door is locked?



More information about the Novalug mailing list