awk -F| ?! How in shell?! 
Author Message
 awk -F| ?! How in shell?!

How can I successfully do this??

                  cat kooky.txt | awk -F| '{print $11}'

kooky.txt contains an unload from Informix and I would like to get the
entire number from the 11'th field. (ie. 20240 then 10440, then 884..
and so on)

01/03/2000|14:10|01/17/2000|15:30|00010010|WIESMAN|JFE|C|Entex|3|
20240|
01/10/2000|09:30|01/17/2000|15:30|00010032|WIESMAN|KTM|C|Entex|3|
10440|
01/18/2000|17:19|01/19/2000|08:03|00010076|ADMIN|AIM|C|Systems|3|
884|
01/25/2000|13:54|01/25/2099|03:00|00010118|WIESMAN|DSC|C|Entex|3|
52069746|

Of course, Bourne shell sees the "|" after the "-F" as a pipe.
How can I get around this!?

(I realise this is much more an awk question than it is a shell
question, but I figured it had enough to do with the shell to xpost to
comp.unix.shell)

Tony!



Wed, 31 Jul 2002 03:00:00 GMT  
 awk -F| ?! How in shell?!


Quote:
> How can I successfully do this??

>                   cat kooky.txt | awk -F| '{print $11}'

> kooky.txt contains an unload from Informix and I would like to get the
> entire number from the 11'th field. (ie. 20240 then 10440, then 884..
> and so on)

> 01/03/2000|14:10|01/17/2000|15:30|00010010|WIESMAN|JFE|C|Entex|3|
> 20240|
> 01/10/2000|09:30|01/17/2000|15:30|00010032|WIESMAN|KTM|C|Entex|3|
> 10440|
> 01/18/2000|17:19|01/19/2000|08:03|00010076|ADMIN|AIM|C|Systems|3|
> 884|
> 01/25/2000|13:54|01/25/2099|03:00|00010118|WIESMAN|DSC|C|Entex|3|
> 52069746|

> Of course, Bourne shell sees the "|" after the "-F" as a pipe.
> How can I get around this!?

> (I realise this is much more an awk question than it is a shell
> question, but I figured it had enough to do with the shell to xpost to
> comp.unix.shell)

> Tony!

Use either -F\| or -F"|" as in

  cat kooky.txt | awk -F\| '{print $11}'

Tip: use of cat and a pipeline here is inefficient,
awk takes a file name, so you can use

  awk -F\| '{print $11}' kooky.txt
  or: awk -F\| '{print $11}' < kooky.txt

--
Regards
()z
-------------------------------------------------
http://www.sorcerer.co.uk/

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 31 Jul 2002 03:00:00 GMT  
 awk -F| ?! How in shell?!

Quote:
> How can I successfully do this??
>                   cat kooky.txt | awk -F| '{print $11}'
> Of course, Bourne shell sees the "|" after the "-F" as a pipe.
> How can I get around this!?
> (I realise this is much more an awk question than it is a shell
> question, but I figured it had enough to do with the shell to xpost to
> comp.unix.shell)

Quoting the "|" in any manner, even with a backslash, is all you need to
do.  (You've got it backwards, BTW--comp.unix.shell is the perfect place
to ask and comp.lang.awk the worst.)

--
Eric Amick
Columbia, MD



Wed, 31 Jul 2002 03:00:00 GMT  
 awk -F| ?! How in shell?!

Quote:


>>                   cat kooky.txt | awk -F| '{print $11}'
>Quoting the "|" in any manner, even with a backslash, is all you need to
>do.  (You've got it backwards, BTW--comp.unix.shell is the perfect place
>to ask and comp.lang.awk the worst.)

And unless you'd like to win a UUOC award, think about getting rid
of that darn cat. You can do this:

awk -F"|" '{print $11}'  kooky.txt
or this:
awk -F'|' '{print $11}'  <kooky.txt
or even this if you want to put the file first like with cat:
<kooky.txt awk -F\| '{print $11}'

Cheers,
Douglas Wilson



Wed, 31 Jul 2002 03:00:00 GMT  
 awk -F| ?! How in shell?!
Try this

awk -F\| '{print $11}'  kooky.txt

Jean Pierre



Quote:
> How can I successfully do this??

>                   cat kooky.txt | awk -F| '{print $11}'

> kooky.txt contains an unload from Informix and I would like to get the
> entire number from the 11'th field. (ie. 20240 then 10440, then 884..
> and so on)

> 01/03/2000|14:10|01/17/2000|15:30|00010010|WIESMAN|JFE|C|Entex|3|
> 20240|
> 01/10/2000|09:30|01/17/2000|15:30|00010032|WIESMAN|KTM|C|Entex|3|
> 10440|
> 01/18/2000|17:19|01/19/2000|08:03|00010076|ADMIN|AIM|C|Systems|3|
> 884|
> 01/25/2000|13:54|01/25/2099|03:00|00010118|WIESMAN|DSC|C|Entex|3|
> 52069746|

> Of course, Bourne shell sees the "|" after the "-F" as a pipe.
> How can I get around this!?

> (I realise this is much more an awk question than it is a shell
> question, but I figured it had enough to do with the shell to xpost to
> comp.unix.shell)

> Tony!



Wed, 31 Jul 2002 03:00:00 GMT  
 awk -F| ?! How in shell?!

: How can I successfully do this??
:                   cat kooky.txt | awk -F| '{print $11}'

First, lose the "cat".
    awk -F\| '{print $11}' kooky.txt

Or even
    <kooky.txt awk -F\| '{print $11}'
If the noun you want before the verb.

: Of course, Bourne shell sees the "|" after the "-F" as a pipe.

Yep.

: (I realise this is much more an awk question than it is a shell
: question, but I figured it had enough to do with the shell to xpost to
: comp.unix.shell)

You were right the first time.  The pipe is a shell special character,
and you have to tell the shell to ignore it.  It has nothing whatever to
do with awk.

--
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

      Consulting                   wrong with a world in which Ken
      Modeling                     Thompson lives in obscurity and
      Training                     Bill Gates is a famous billionaire.
//////////////////////////////////////////////////////////////////////



Tue, 20 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. FS: AWK Library

2. FS Behaviour differs between awk and gawk

3. AWK-Script to set a shell variable (Win32) ?

4. Return value from awk snipet via korn shell subroutine

5. Passing command line variables to AWK in shell script

6. using awk in a shell script...

7. Substituting single quotes from Perl via shell using awk and gsub

8. shell/awk combo puzzler

9. setting shell variables with results from awk

10. trying to call awk from within a shell script

11. A simple question regarding shell scripts and awk

12. shell-parameter for outputfile in awk

 

 
Powered by phpBB® Forum Software