Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk pipeline 2

Status
Not open for further replies.

ovince

Programmer
Feb 27, 2007
55
FR
hi,

I would like to use file names within awk so I tried something like this:


for file in box*.dat;
do awk 'BEGIN {"echo $file" | getline fl; close("echo $file"); print fl} ' $file
; done

any idea what I do wrong?

thanks
 
In fact, the real question is: what do you want to do ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I would like to take ALL box*.dat files, to calculate average of say coulumn 4, and to write out the results into different files that has almost the same name (say DHbox*.tex). What is under * should remain in order to distinguish the files
 
thanks. Steel I would like to know why the preliminary idea does not work and how to introduce file names into awk to be able to work with within awk
 
Hi

ovince said:
Steel I would like to know why the preliminary idea does not work
Because the code string with the $file variable was delimited with single quotes ( ' ). The $file is a shell variable and the shell does not expand the variable names in strings quoted with single quotes.
ovince said:
how to introduce file names into awk to be able to work with within awk
Code:
awk '{print "the file is : [red]'[/red]$file[red]'[/red]"}' $file

[gray]# or[/gray]

awk [red]"[/red]{print [red]\[/red]"the file is : $file[red]\[/red]"}[red]"[/red] $file

[gray]# or[/gray]

awk [red]-vfile=$file[/red] '{print "the file is : "[red]file[/red]}' $file

[gray]# or[/gray]

awk '{print "the file is : "[red]FILENAME[/red]}' $file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top