Showing results for 
Search instead for 
Do you mean 

select fields from a report

SOLVED
Go to Solution
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
Honored Contributor 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
Acclaimed Contributor Acclaimed Contributor

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.
Honored Contributor 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
Honored Contributor 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...
Honored Contributor 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 $
Honored Contributor 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
Respected Contributor 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