Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

AWK question  comma separated file

Posted on 2003-03-04
6
Medium Priority
?
1,168 Views
Last Modified: 2013-12-26
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 ?
0
Comment
Question by:webstep
  • 3
5 Comments
 
LVL 2

Expert Comment

by:jimbb
ID: 8066926
#!/usr/bin/awk -f

BEGIN {OFS = ","}

{
        for (nf = 1; nf < NF; nf++) {
                gsub(/^[^=]+=/, "", $nf)
                printf("%s%s", $nf, OFS)
        }
        gsub(/^[^=]+=/, "", $NF)
        print $NF
}
0
 
LVL 2

Expert Comment

by:jimbb
ID: 8066939
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 = ","}
0
 
LVL 4

Expert Comment

by:Vinit Kain
ID: 8071976
other then awk you can use sed or simple tr

try this

cat file_name|tr '        ' ',' >outputfile

or

cat ahsgjd|sed "s/     /,/g"
0
 
LVL 2

Accepted Solution

by:
jimbb earned 200 total points
ID: 8073362
He also said he wants to remove the header= portions of the fields, the awk script I posted does that (and should also be safe if the data portion contained an '=').
0
 
LVL 18

Expert Comment

by:liddler
ID: 9827176
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question