Link to home
Start Free TrialLog in
Avatar of webstep
webstep

asked on

AWK question comma separated file

AWK question
I have a file that I wish to make in to a comma separated file in unix also to removed some of the headings eg virtual_me..

28/02/2003     18:21:56     eghead     cpu=32     disk=6     free_swap=4102160     virtual_memory=192457848     page_kbytes_sec=2     pkts=600.6     colls=0

the filed are separated by tabs


How and what commands would I use
AWK ?
Avatar of jimbb
jimbb

#!/usr/bin/awk -f

BEGIN {OFS = ","}

{
        for (nf = 1; nf < NF; nf++) {
                gsub(/^[^=]+=/, "", $nf)
                printf("%s%s", $nf, OFS)
        }
        gsub(/^[^=]+=/, "", $NF)
        print $NF
}
P.S. The above script assumes you won't have any regular spaces in the fields.  If that can happen, then make sure you narrow down the awk field separator character to a Tab, like this:

BEGIN {FS = "\t"; OFS = ","}
other then awk you can use sed or simple tr

try this

cat file_name|tr '        ' ',' >outputfile

or

cat ahsgjd|sed "s/     /,/g"
ASKER CERTIFIED SOLUTION
Avatar of jimbb
jimbb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by jimbb

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer