MACSCRPT Archives

November 2009

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Steven D. Majewski" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 3 Nov 2009 19:51:54 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (40 lines)
On Nov 3, 2009, at 3:08 PM, [log in to unmask] wrote:

> I need some quick GREP advice.
>
> I'm working with a pipe delimited data file in this format:
>
> 114|20090826|00:00|N|1800|8005082|6719954|TVPG|L||CC|Stereo|N|Color|| 
> N|N|N|4:3 Fullscreen|N||||Y
>
> The 6th and 7th items in the each row of data (|8005082|6719954|,  
> from the example) are references to data in other files.
>
> So what I need is a grep command that will give me 2 lists, one  
> containing the 6th number from each row and one containing the 7th.
>
> The lists could be pipe, comma, tab or return delimited
>
> I'm fairly sure this can be done via GREP, but I don't know where to  
> start.
>
> Any suggestions?


cut -d'|' -f6

will give you the 6th column delimited by '|'

you can pass that thru:  tr '\n' ','

for example, to change the newlines of each row into commas if that's  
what you want.

'paste' is the inverse of 'cut', and will join columns together.
But if what you want is to turn the columns into rows and join them,  
then
you can just concatenate the rows produced by piping thru 'tr' with  
'cat'

-- Steve Majewski

ATOM RSS1 RSS2