Typically you would use awk to process the file instead of using bash as a filter. The problem with things to awk is that the single quote prevents bash from doing substitution making awk try to figure out what to print and maybe printing nothing as the variable isn't set.
On Tue, Jan 27, 2015 at 10:56 AM, Daniel Herrington <[email protected]> wrote: > On Tue, Jan 27, 2015 at 10:25 AM, Daniel Herrington <[email protected]> > wrote: > > > > > > > On Tue, Jan 27, 2015 at 10:15 AM, Rich Shepard <[email protected] > > > > wrote: > > > >> On Tue, 27 Jan 2015, Daniel Herrington wrote: > >> > >> > host=$(awk '{ print "wtf:" $m }') > >> > >> Daniel, > >> > >> Your awk statement begins by printing the string, wtf: and that is > why > >> you > >> see that in the output. > >> > >> As Paul wrote, show us the input file and we can examine the output > >> relative to it. > >> > >> Regards, > >> > >> Rich > >> _______________________________________________ > >> PLUG mailing list > >> [email protected] > >> http://lists.pdxlinux.org/mailman/listinfo/plug > >> > > > > The file: > > foo > > bar > > baz > > bunt > > > > awk seems to be able to read bar in the file before the echo "before > > testing:" statement(line 8). Actually, it clearly has to, I just don't > > understand why: > > > > Starting script > > before testing: foo > > foo :: wtf:bar > > wtf:baz > > wtf:bunt > > > > The code for "before testing: should be read for each run of the for > loop, > > and should occur before the awk gets called. If I comment out the awk > line, > > I get the loop behavior I would expect. In fact, I think the for loop is > > actually superflous, as the while itself should just loop. > > > > Also: > > > > SunOS svanyc587 5.10 Generic_150400-13 sun4v sparc sun4v > > > > -- > > Daniel B. Herrington > > > > Ok, it has something to do with the way I'm passing in the variable to awk. > The original statement: > > host=$(awk '{ print "wtf:" $m }') > > works when I do: > > host=$( echo $m | awk '{ print "wtf:" $1 }') > > The way I'm calling awk is the issue. It also seems it would be better to > just call awk against the file directly. > > thanks all, > > -- > Daniel B. Herrington > _______________________________________________ > PLUG mailing list > [email protected] > http://lists.pdxlinux.org/mailman/listinfo/plug > _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
