[olug] bash help (awk/sed)

David Walker olug at grax.com
Fri Jun 18 11:10:08 UTC 2004


with filename variable using bash's variable substitution:
filename=pg0001.txt && egrep -o [0-9]{6}-[A-F] $filename | 
awk "{ print \$1 \",$filename\"}"

or

just output the filename from grep and the format the output:
filename=pg0001.txt && egrep -H -o [0-9]{6}-[A-F] $filename | 
awk -F ":" '{ printf "%s,%s\n",$2,$1}'

On Friday 18 June 2004 12:37 am, Eric Pierce wrote:
> Ok, I'm stumped.
>
> I'm trying to pull from a file (several files actually) all six digit
> combinations followed by a dash and a letter A-F (ex. 123456-D).  Then I
> want to append a comma AND the filename that it is pulling from.
>
> Example.
> 123456-D,file01.txt
> 654321-D,file01.txt
> ....
>
> Here's what I have so far:
> filename=pg0001.txt && egrep -o [0-9]{6}-[A-F] $filename | awk '{ print $1
> ","}'
>
> The output so far is 90% there.  It looks like this:
> 300150-D,
> 300141-C,
> 300258-D,
> 300132-A,
> ....
>
> But I can't figure out how to append the $filename after the comma in each
> line.  I can't get Awk to resolve the $filename variable.  I've tried a
> billion different syntax combinations sticking $filename on the end of the
> Awk part, but to no avail.
>
> I also have a sed version, but the problem is exactly the same.
> filename=pg0001.txt && egrep -o [0-9]{6}-[A-F] $filename | sed -n
> 's/\(.*\)/\1,/p
>
> Any ideas anyone?
> Thanks,
> Eric Pierce
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.
> http://promotions.yahoo.com/new_mail
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug


More information about the OLUG mailing list