[Novalug] sed syntax question
donjr
djr1952@hotpop.com
Sat Mar 10 07:23:46 EST 2007
Megan,
If you always have 'awk' aviable?
I found a simpler way to do everything and it don't care what SHELL
the operators is using.
As one long line:
awk '{a=split($0,ar,/ bytes/);for(i=1;i < a;i++){b=split(ar[i],br," ");
tot+=br[b];print br[b];}; print "=========="; print tot;}' ftp2u.html
Or Split up with comments {and ready to paste into a file}:
-------------------------
#!/usr/bin/awk -f
# call as 'foo.awk ftp2u.html'
{
a=split($0,ar,/ bytes/); # split the line apart on the "bytes" sep
for(i=1;i < a;i++) # a is always one more then number of transfers
{
b=split(ar[i],br," "); # Now split one array element on space
tot+=br[b]; # The last entry is always the number of bytes
print br[b]; # transferred for this entry.
};
print "==========";
print tot; # print the total transferred
}
----------------------------
On Fri, 2007-03-09 at 22:29 -0500, C Megan Larko wrote:
> Hello Don,
>
> On Fri, Mar 09, 2007 at 06:57:34PM -0500, Groves Don wrote:
> > Megan,
< large chunk cut out >
> > 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