Org file
192.168.1.10 d:\adir\xdir
192.168.1.11 d:\bdir\ydir
want to covert it into
robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\adir
robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\bbdir
Org file
192.168.1.10 d:\adir\xdir
192.168.1.11 d:\bdir\ydir
want to covert it into
robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\adir
robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\bbdir
what have you tried so far?
And why do you need to invoke 'bash command inside awk'?
able to achieve atleast,
robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\
robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\
awk '{printf "robocopy \\\\"$1 "\\" $2 "\\ecm\*.log some_localdir\\\n"}' ecm_app_server_list.txt | sed 's/:/$/'
now want
robocopy \\192.168.1.10\d$\adir\xdir\log* some_localdir\xdir
robocopy \\192.168.1.10\d$\adir\ydir\log* some_localdir\ydir
now I want to use following bash command to achieve this ..
awk '{printf "robocopy \\\\"$1 "\\" $2 "\\ecm\*.log some_localdir\\$(cut -d ":" -f3 $2)`\n"}' ecm_app_server_list.txt | sed 's/:/$/'
but not working .. giving error
using command substitution:
$(some command)
is NOT how you call non-awk commands from awk.
What you want to do can be achieved with a little awk magic....just awk.
split(,,sep)
so somewhere before your print statement, you need a split() statement, like so:
split($2, array1, "\\")
so then, lets use the "192.168.1.10 d:\adir\xdir" line as an example:
array1[1] is "d:"
array1[2] is "adir"
array1[3] is "xdir"
nawk -f ydk.awk myFile
ydk.awk:
function rindex(str,c)
{
return match(str,"\\" c "[^\\" c "]*$")? RSTART : 0
}
{
split($2, f2, ":")
print "robocopy \\\\" $1 "\\" f2[1] "$" f2[2] "\log* somelocaldir\\" substr($2,1, rindex($2,"\\")-1)
}
excellent.. thanks..
split is really good..
any good website for reference having details about awk functions