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

Need help to execute Unix commands from awk script ? 1

Status
Not open for further replies.

rogers42

Technical User
Mar 30, 2007
64
CA
Hi Folks,

I am trying to strip away the last five characters from the file name. Following is an example

Input: file1.done
Output: file1

My nawk script is as follows

Code:
BEGIN {
  # Set the field separator to white space
  FS=" "
}
{
    print | "mv " $9 " " substr($9, 1,length($9)-5)
}

I am executing the script as follows

Code:
ls -ltrh file* | nawk -f rename_files.awk

How can I execute the move command from within my awk script?

Thanks in advance

rogers
 
Replace this:
print | "mv " $9 " " substr($9, 1,length($9)-5)
with this:
system("mv " $9 " " substr($9, 1,length($9)-5))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

That's exactly what I was looking for.

Thanks

rogers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top