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!

Ambiguous error in script to rename a file

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
I need to get everything between two words then put
that in a file renamed with the original filenameand "-body" and the end of it . file1-body
I keep on getting $file-body: Ambiguous error.

What am I doing wrong?

------------------
#!/bin/csh -f

foreach file ('cat ./filelist')

sed -n '/NET/,/TEST/p' $file > $file-body

end
----------------

Thanks,
olmos
 
Try [tt]${file}[/tt] instead of [tt]$file[/tt]. The braces eliminate the ambiguity.

I don't know C-shell, but in other shells this would help.

Hope this helps.
 
It looks like you are re-directing the output of the sed -n . . . command to the contents of a variable called file-body. Has that variable been previously defined ?
Additionally you are creating a new file each time you go round the loop. If you want to append the output then use >> instead of > .

I hope that helps. Please feel free to re-post further questions.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top