Text processing, probably simple for you gurus out there.... 
Author Message
 Text processing, probably simple for you gurus out there....

I have a bash script that is parsing data from a database text file.
The data looks like this:

10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
10020125/bar/normal//enable///, etc, etc, etc.

These keep going on for awhile with some lines containing possibly 10 or
more entries seperated by commas.  What I need to do is sort out the id
number field e.g. 10020123 from every set of data.  How would i do so
with awk?



Sun, 12 Jan 2003 03:00:00 GMT  
 Text processing, probably simple for you gurus out there....

Quote:

>I have a bash script that is parsing data from a database text file.
>The data looks like this:

>10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
>10020125/bar/normal//enable///, etc, etc, etc.

>These keep going on for awhile with some lines containing possibly 10 or
>more entries seperated by commas.  What I need to do is sort out the id
>number field e.g. 10020123 from every set of data.  How would i do so
>with awk?

I'd probably do it like this:

tr '[,]' '[\012]' infile | awk -F/ '{print $1}'

the tr part changes commas to newlines, putting each entry on a separate
line, and then the awk part uses the slash as a field separator, and
I just print the first field of each entry (record/line).

man tr
man awk

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 12 Jan 2003 03:00:00 GMT  
 Text processing, probably simple for you gurus out there....

Quote:



>>I have a bash script that is parsing data from a database text file.
>>The data looks like this:

>>10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
>>10020125/bar/normal//enable///, etc, etc, etc.

>>These keep going on for awhile with some lines containing possibly 10 or
>>more entries seperated by commas.  What I need to do is sort out the id
>>number field e.g. 10020123 from every set of data.  How would i do so
>>with awk?

>I'd probably do it like this:

>tr '[,]' '[\012]' infile | awk -F/ '{print $1}'

this should be:

tr '[,]' '[\012]' < infile | awk -F/ '{print $1}'

Sorry about the typo.

Chuck Demas
Needham, Mass.

Quote:

>the tr part changes commas to newlines, putting each entry on a separate
>line, and then the awk part uses the slash as a field separator, and
>I just print the first field of each entry (record/line).

>man tr
>man awk

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 12 Jan 2003 03:00:00 GMT  
 Text processing, probably simple for you gurus out there....
Im going to assume that  [/012] is ascii for \n ? Is that correct?
Quote:





> >>I have a bash script that is parsing data from a database text file.
> >>The data looks like this:

> >>10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
> >>10020125/bar/normal//enable///, etc, etc, etc.

> >>These keep going on for awhile with some lines containing possibly 10 or
> >>more entries seperated by commas.  What I need to do is sort out the id
> >>number field e.g. 10020123 from every set of data.  How would i do so
> >>with awk?

> >I'd probably do it like this:

> >tr '[,]' '[\012]' infile | awk -F/ '{print $1}'

> this should be:

> tr '[,]' '[\012]' < infile | awk -F/ '{print $1}'

> Sorry about the typo.

> Chuck Demas
> Needham, Mass.

> >the tr part changes commas to newlines, putting each entry on a separate
> >line, and then the awk part uses the slash as a field separator, and
> >I just print the first field of each entry (record/line).

> >man tr
> >man awk

> --
>   Eat Healthy    |   _ _   | Nothing would be done at all,

>   Die Anyway     |    v    | That no one could find fault with it.




Sun, 12 Jan 2003 03:00:00 GMT  
 Text processing, probably simple for you gurus out there....
Quote:
> Nevermind, octal i mean....is that right?
> Im going to assume that  [/012] is ascii for \n ? Is that correct?





> > >>I have a bash script that is parsing data from a database text file.
> > >>The data looks like this:

> > >>10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
> > >>10020125/bar/normal//enable///, etc, etc, etc.

> > >>These keep going on for awhile with some lines containing possibly 10 or
> > >>more entries seperated by commas.  What I need to do is sort out the id
> > >>number field e.g. 10020123 from every set of data.  How would i do so
> > >>with awk?

> > >I'd probably do it like this:

> > >tr '[,]' '[\012]' infile | awk -F/ '{print $1}'

> > this should be:

> > tr '[,]' '[\012]' < infile | awk -F/ '{print $1}'

> > Sorry about the typo.

> > Chuck Demas
> > Needham, Mass.

> > >the tr part changes commas to newlines, putting each entry on a separate
> > >line, and then the awk part uses the slash as a field separator, and
> > >I just print the first field of each entry (record/line).

> > >man tr
> > >man awk

> > --
> >   Eat Healthy    |   _ _   | Nothing would be done at all,

> >   Die Anyway     |    v    | That no one could find fault with it.




Sun, 12 Jan 2003 03:00:00 GMT  
 Text processing, probably simple for you gurus out there....

Quote:

>> Nevermind, octal i mean....is that right?

>> Im going to assume that  [/012] is ascii for \n ? Is that correct?

\012 is the octal representation for a unix newline.  The square
brackets are there to assure compatibility to many/other forms of unix.

on most systems these would have worked too:

tr ',' '\n' < infile
tr ',' '\012' < infile

Chuck Demas
Needham, Mass.

Quote:





>> > >>I have a bash script that is parsing data from a database text file.
>> > >>The data looks like this:

>> > >>10020123/soulslinger/normal//enable///, 10020124/foo/normal//enable///,
>> > >>10020125/bar/normal//enable///, etc, etc, etc.

>> > >>These keep going on for awhile with some lines containing possibly 10 or
>> > >>more entries seperated by commas.  What I need to do is sort out the id
>> > >>number field e.g. 10020123 from every set of data.  How would i do so
>> > >>with awk?

>> > >I'd probably do it like this:

>> > >tr '[,]' '[\012]' infile | awk -F/ '{print $1}'

>> > this should be:

>> > tr '[,]' '[\012]' < infile | awk -F/ '{print $1}'

>> > Sorry about the typo.

>> > Chuck Demas
>> > Needham, Mass.

>> > >the tr part changes commas to newlines, putting each entry on a separate
>> > >line, and then the awk part uses the slash as a field separator, and
>> > >I just print the first field of each entry (record/line).

>> > >man tr
>> > >man awk

>> > --
>> >   Eat Healthy    |   _ _   | Nothing would be done at all,

>> >   Die Anyway     |    v    | That no one could find fault with it.


--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 12 Jan 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Something probably simple...

2. probably a simple problem

3. I have a very simple..probably stupid..clipper question

4. Probably a simple newbie question...

5. Problem (probably simple) that I can't solve

6. Probably a simple one

7. Probably a simple question

8. Help! Probably a simple problem

9. Probably really simple but...

10. Please help with query - probably very simple...

11. Problem with a piece of code (probably a simple one)

12. Help : IndexError - probably pretty simple

 

 
Powered by phpBB® Forum Software