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!

modify and rename file

Status
Not open for further replies.

Josewr

Technical User
Feb 28, 2005
15
US
I need to modify a file and rename it. Tried:

awk -f modfile oldname new=newfile.fmt
(Tried also: awk -f modfile oldname new="newfile.fmt")

and modfile has lines such as

{print " mod1 " > new}
{print " mod2 " > new}

The modfile works if I change the lines to read:

{print " mod1 " > "newfile.fmt"}
{print " mod2 " > "newfile.fmt"}
rather then passing it from the command line

Thanks
 
Hi

Just an idea. Specify the new name as [tt]-v new="newfile.fmt"[/tt]. As you wrote it, the [tt]new[/tt] variable will be created after the BEGIN blocks, but if you specify with the [tt]-v[/tt], will be created before the execution of BEGINs.

Feherke.
 
Sorry, but I had tried that also. I was just trying to simplify the Posting. This are the important lines on the program look like:

BEGIN {getline
print $0 > new}

{if (length($2) >= 76){
{print "-- * " > new}
{print "-- * 8/3/05 Jose Changed to New Specs, 18 May 2005. " >new}
{print "-- * " > new}
{print "-- * " > new}
}}

{print $0 > new}

And the command line:

gawk -f ModifyFile1.awk OldFileName.fmt -v new="NewFile.fmt"

I get the following error:

gawk: ModifyFile1.awk:3: (FILENAME=OldFileName.fmt FNR=1) fatal: expression for `>' redirection has null string value

Therefore, is not reading the variable on the first line.
I may have more {} than I need. I am new at this.
Thanks.
 
Try this:
gawk -v new="NewFile.fmt" -f ModifyFile1.awk OldFileName.fmt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks to you both, feherke and PH! Looks like I had the cart before the horse.

It works now!!

Jose
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top