[PLUG] bash and awk strangeness

Daniel Herrington herda05 at gmail.com
Tue Jan 27 18:11:54 UTC 2015


No problem. The file:

[571][DEV machine: /u/p576656/work]$ cat bat
foo
bar
baz
bunt


On Tue, Jan 27, 2015 at 10:08 AM, Paul Heinlein <heinlein at madboa.com> wrote:

> Sorry for the top-post, but...
>
> It'd be helpful if you posted an example of the file you're trying to
> read. It's difficult to understand what you want to happen.
>
>
> On Tue, 27 Jan 2015, Daniel Herrington wrote:
>
>  All,
>>
>> I'm clearly doing something wrong, and clearly am missing something about
>> bash and awk interaction. My script:
>>
>> #!/usr/bin/bash
>>
>> echo "Starting script"
>> while read line
>> do
>>    for m in $line
>>    do
>>      echo "before testing: $line :: $m"
>>      host=$(awk '{ print "wtf:" $m }')
>>      echo "$line :: $m :: $host"
>>    done
>> done < $1
>>
>> It reads a file and outputs the list of names in the file, and I though
>> would be like:
>> Starting script
>> before testing: foo :: foo
>> foo :: foo :: foo
>> before testing: bar :: bar
>> bar :: bar :: bar
>> before testing: baz :: baz
>> baz :: baz :: baz
>> before testing: bunt :: bunt
>> bunt :: bunt :: bunt
>>
>> However, what I get is:
>> Starting script
>> before testing: foo :: foo
>> foo :: foo :: wtf:bar
>> wtf:baz
>> wtf:bunt
>>
>> I have isolated it to the awk command printing out the actual file
>> contents. However, I'm not sure how awk is looping through anything, as it
>> only should should have access to $line, and $line is a single line from
>> the file. It seems like awk is not in the loop?
>>
>> thanks,
>>
>>
>>
> --
> Paul Heinlein
> heinlein at madboa.com
> 45°38' N, 122°6' W
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>
>


-- 
Daniel B. Herrington



More information about the PLUG mailing list