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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK write file to different directory

Status
Not open for further replies.

stevenawk

Programmer
Nov 12, 2008
9
DE
Hi,

program:

echo -n "Enter the file to process: "
read inputFile
date
nawk '
/^\[.*\]/ {
id=$3
f=id".txt" # assign f
sub(/{/,"",f) # replace { with nothing, in variable f
sub(/}/,"",f) # replace } with nothing, in variable f
time=$1" "$2 # timestamp is column 1 and 2
print>>f # use append command for writing line
close(f) # close the file
next
}
{
print time" "id" "$0>>f
close(f) # close file
}
' $inputFile
date # display time to see how long it took


Why oh why can i not get it to make the files in another directory (results for e.g.). I have tried every combo of quotes.

Please help,

S.
 
Hi

S said:
Why oh why can i not get it to make the files in another directory (results for e.g.).
While you posted none of the tried combination I can only guess what you done.
Code:
[gray]# wrong[/gray]

print>>"results/"f

[gray]# correct[/gray]

print>>[red]([/red]"results/"f[red])[/red]


Feherke.
 
Hi

thanks again Feherke, i did try your wrong combo, but i have never even heard of brackets around it!

cheers

Steve
 
I don't think it's documented anywhere either, but the >> operator seems to have tighter binding than the implicit string concatenation in awk. I was equally confused when I encountered this one...

Another workaround would be:

Code:
file="results/"f
print>>file

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top