I would like to add commas into numbers to make them more readable. Such as, when awk comes across a number, add commas to make "31231104990" into "31,231,104,990". Is this possible with awk or another program?
Thank you Jean Pierre, that works great for just a number, but actually, here is what I'm trying to do:
I'm using the following script to get only the pertinent information from a backup exec log file and sort it by size, big to small.
awk '/Backup of/{printf("%s ",$3)};/Processed/{printf("%s\n",$2)};/Job Operation - Verify/{exit}' c:/temp/bex.txt | sed s/\"//g | sed s/,//g | sort -r -n -k 2
I strip the commas from the number in order to allow the sort to work, but would like to put the commas back in to make it easier to read. Could there be a way within awk to sort the list without removing the commas in the first place? Below is a sample of the "bex.txt" I'm pulling from:
===========================================================
Set Information - \\PCABC\C:
Backup Set Information
Family Name: "Media created 7:00:07 PM 3/12/2004 - Fri Full Backup - Work / User Job"
Backup of "\\PCABC\C: "
Backup set #12 on storage media #6
Backup set description: "Fri Full Backup - User Job"
Backup Type: FULL - Back Up Files - Reset Archive Bit
Backup started on 3/27/2004 at 1:23:45 AM.
Backup completed on 3/27/2004 at 2:10:06 AM.
Backup Set Summary
Backed up 7613 files in 486 directories.
Processed 2,994,485,909 bytes in 46 minutes and 21 seconds.
Throughput rate: 61.6 MB/min
============================================================
That works great! Thank you so much for your help. I should have realized that I could just continue the pipe on into the sed. As long as we're on a roll here, is there a resonably handy way to pad the spaces between the system name/share and the size so that the size portion is right justified? Its not really needed, but it would make it easier to read. Below is a larger sample output:
Hey PHV,
I tried it and got the following error:
/cygdrive/c/docume~1/saw.TERNION/desktop-> domaxbackups.sh
awk: cmd. line:3: /Processed/{key=$2;gsub(/,/,"",key)printf("%s %s %s\n",key,sha
re,$2)}
awk: cmd. line:3: ^ syntax error
The syntax error is pointing to the printf on the "Processed" line. I'm not sure how the "gsub" part works, but it look interesting.
thanks,
Scott
Sorry for the typo, just add a semi-colon before the printf, like this:
awk '
/Backup of/{share=$3;gsub(/"/,"",share)}
/Processed/{key=$2;gsub(/,/,"",key)[highlight];[/highlight]printf("%s %-20s %16s\n",key,share,$2)}
/Job Operation - Verify/{exit}
' c:/temp/bex.txt | sort -r -n | sed 's!^[ 0-9]*!!'
Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
Hey PHV, Yeah, I just found that I forgot to put in the semi-colon before the printf. I added it and it worked great like Jean Pierre's example. Both ways work so slick. Thank you both for your help!
If anyone knows of a handy way to right-justify the number while keeping the system name left-justified, that would be nice, but it would just be an extra kind of thing; not a requirement.
Oop, my bad. I apologize, I missed it. I just thought that the bolded letters in the printf above were an HTML hiccup of the site here. Actually, it was a hiccup of my brain. That works perfect! Again, many thanks!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.