Problem with Echo (I think) 
Author Message
 Problem with Echo (I think)

Hello

I am trying to write a script to parse  the index file from a gnats
db. An example of some of the file is shown below.

drivers/1|default|egor|open|no|Driver Problem using Spin Locks
drivers/2|default|andy|open|no|Memory Map Problem

I thought because each field is seperated by | this lends itself to
awk very nicely.  I'm sort of new to linux and awk, but am picking it
up I think.

The script I wrote is shown below

for x in `cat $1`; do
   echo $x | awk -F\| '($4 == open) {print $3 " " $6}'

done

The problem I'm having is $6 only seems to pick up the first word, so
it would only print out

     egor Driver
     andy Memory

What I wanted to happen was it would print out the name and full
synopsis.  I was then going to put it into a mail.

I'm pretty sure that awk isn't the problem cause when I run this from
the command line using awk -F\| '($4 == "open"){print $3 " " $6}' its
just fine, so I figured echo was doing something to $x.

I'm sure that this isn't the best way of doing this, but I'm only
learning, and this is the way I came up with, so please don't slag me
off, just for learning.

Thanks for any help.

Best Regards

Andy



Sat, 09 Apr 2005 17:38:17 GMT  
 Problem with Echo (I think)
You guessed correctly, kind of. The actual problem comes in in the for
statement. The output of the cat has the \n replaced by space and the
resulting stream of "words" is returned, one at at time, as $x. The
simplest solution is to use none of the for, echo or cat. The bare awk
should work swimmingly:

   awk -F\| '($4 == open) {print $3 " " $6}' $1

should do what you want.

Quote:

> Hello

> I am trying to write a script to parse  the index file from a gnats
> db. An example of some of the file is shown below.

> drivers/1|default|egor|open|no|Driver Problem using Spin Locks
> drivers/2|default|andy|open|no|Memory Map Problem

> I thought because each field is seperated by | this lends itself to
> awk very nicely.  I'm sort of new to linux and awk, but am picking it
> up I think.

> The script I wrote is shown below

> for x in `cat $1`; do
>    echo $x | awk -F\| '($4 == open) {print $3 " " $6}'

> done

> The problem I'm having is $6 only seems to pick up the first word, so
> it would only print out

>      egor Driver
>      andy Memory

> What I wanted to happen was it would print out the name and full
> synopsis.  I was then going to put it into a mail.

> I'm pretty sure that awk isn't the problem cause when I run this from
> the command line using awk -F\| '($4 == "open"){print $3 " " $6}' its
> just fine, so I figured echo was doing something to $x.

> I'm sure that this isn't the best way of doing this, but I'm only
> learning, and this is the way I came up with, so please don't slag me
> off, just for learning.

> Thanks for any help.

> Best Regards

> Andy



Sat, 09 Apr 2005 21:46:33 GMT  
 Problem with Echo (I think)


Quote:
> Hello

> I am trying to write a script to parse  the index file from a gnats
> db. An example of some of the file is shown below.

> drivers/1|default|egor|open|no|Driver Problem using Spin Locks
> drivers/2|default|andy|open|no|Memory Map Problem

> I thought because each field is seperated by | this lends itself to
> awk very nicely.  I'm sort of new to linux and awk, but am picking it
> up I think.

> The script I wrote is shown below

> for x in `cat $1`; do
>    echo $x | awk -F\| '($4 == open) {print $3 " " $6}'

> done

> The problem I'm having is $6 only seems to pick up the first word, so
> it would only print out

>      egor Driver
>      andy Memory

> What I wanted to happen was it would print out the name and full
> synopsis.  I was then going to put it into a mail.

> I'm pretty sure that awk isn't the problem cause when I run this from
> the command line using awk -F\| '($4 == "open"){print $3 " " $6}' its
> just fine, so I figured echo was doing something to $x.

Dont use "echo"?? I dont think you need a for loop either,
just read the file in:

awk -F\| '($4 == "open"){print $3,$6}' ${1}



Sat, 09 Apr 2005 23:17:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem Installing PIL (module search path problem I think)

2. Expect echo problem

3. Problems disabling send echo

4. Newbie:'Entry' echo problem Unix/Win95

5. Newbie:SpecTcl 'Entry' echo problem

6. echo problem with tcl 7.5 7.6 on Solaris 2.5.1

7. To think or not to think ;-)

8. Thinking about thinking

9. Thinking about thinking

10. Thinking about thinking

 

 
Powered by phpBB® Forum Software