Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

select fields from a report

SOLVED
Go to solution
Dave Walley
Frequent Advisor

select fields from a report

Hi.

A program generates a line of test delimited by |, I have now been asked to extract from this report a number of different fields namely the 4,6 and 10 (these may change from time to time). The fields are not of fixed length and the line can be over a 1000 characters long. I attach a portion of the line. Remember although the line may appear on many lines it is all contained in one line.

I look forward to your responses.


Thanking you

Dave
why do i do this to myself
8 REPLIES
Patrick Wallek
Honored Contributor

Re: select fields from a report

The easiest way I can think of would be to utilize awk, or if awk can't handle a line of that length, then gnu awk (gawk - http://hpux.connect.org.uk/hppd/hpux/Gnu/gawk-3.1.0/ )

I would do something like:

# awk -F| '{ print $4,$6,$10 } filename
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: select fields from a report

This is trivially simple as long as any one input line does not exceed 3,000 characters - if so you need the Gnu version of awk.

cat myfile | awk -F '|' '{print $4,$6,$10}'
If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: select fields from a report


cat filename|cut -d"|" -f4,6,10

or

cat filename|awk -F\| '{print $4," ",$6," ",$10;}'

live free or die
harry
Live Free or Die
Rodney Hills
Honored Contributor

Re: select fields from a report

awk can do this simply-

awk -F\| '{print $4,$6,$10}' otfile

-- Rod Hills
There be dragons...
Sachin Patel
Honored Contributor

Re: select fields from a report

use awk for it

cat filename | awk -F| '{print $4 $6 $10}'

Sachin
Is photography a hobby or another way to spend $
John Palmer
Honored Contributor

Re: select fields from a report

Hi Dave,

I agree with Patrick on awk but you'll have to quote the pipe sign. Something like

awk -F '|' '{print $4 " " $6 " " $10}'

Regards,
John
Magdi KAMAL
Respected Contributor

Re: select fields from a report

Hi Dave,

# awk -F '|' '{print $4, $6, $10}' fileToBeAnalzed

Will produce what you are looking for since each line within your file is not exceeding 3000 characters.

Magdi

Re: select fields from a report

Hi

awk -F '|' '{print $4 " " $6 " " $10}'

is the simplest way to extract the columns.

Did this solve your problem ? OR you still want to load this extracted data to aother database/table ?

Raju