?
Solved

AWK question  comma separated file

Posted on 2003-03-04
6
Medium Priority
?
1,166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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