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

Call Script with parameters

Status
Not open for further replies.

bubble99

Programmer
Nov 12, 2002
4
0
0
DE
Hi,

i wrote a script that reads (with getline) each row and and writes it to a target folder. The original file is split into parts, the delimiter is defined in the script.
i tried to call a awk script with 2 parameters:
awk -f Split.awk <file to split> <target folder>
awk -f Split.awk c:\awk\file.txt c:\awk\folder
The script:
BEGIN{
file = ARGV[1]
Folder = ARGV[2]
strOutfileName = &quot;File_&quot;
counter = 0
out = (Folder strOutfileName counter &quot;.txt&quot;)
}

{
getline < file

if (/^xxx/){
close(out)
++counter
out = (Folder strOutfileName counter &quot;.txt&quot;)
}

print > out
}


end{
close(out)
}

The file does its job but gives me an errormessage:
awk: Split.awk:52: (FILENAME=c:\awk\file.txt FNR=6240) fatal: cannot open file
`c:\awk\folder\' for reading (No such file or directory)


CAN ANYBODY GIVE ME A TIP??
THANXXX
 
Awk see's all args as filenames in the main section.
You could try:
awk -v Folder=&quot;c:\awk\folder&quot; filename
 
Hi Marsd
Thank you, it works!
bubble99
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top