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!

AWK Script

Status
Not open for further replies.

sethu

Programmer
Apr 15, 2000
29
0
0
US
Hi Experts,

I am very new to AWK. The task for me is to do the following.

1. The input file looks like this

"NAME1" "/dir1/dir2/dirA/file1_name"
"NAME2" "/dir1/dir2/dirB/file2_name"
"NAME3" "/dir1/dir2/dirC/file3_name"
"NAME4" "/dir1/dir2/dirD/file4_name"
"NAME5" "/dir1/dir2/dirE/file5_name"
"NAME6" "/dir1/dir2/dirF/file6_name"

I want to print the output to a file. The output file should read like this. command1, command2, command3 are known commands.

command1 NAME1 command2
cp file1_name /dir3/dir4/file1_name
command1 NAME1 command3

command1 NAME2 command2
cp file2_name /dir3/dir4/file2_name
command NAME2 command3


and so on ...........


--Sethu
 
Here is ...

awk -F '"' '
{
Nb=split($4,Word,"\/")
printf("command1 %s command2\n" , $2)
printf("cp %s %s\n" , Word[Nb] , $4)
printf("command %s command3\n" , $2)
print ""
}' toto.txt

where toto.txt contains your data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top