I have a requirement of extracting the 2nd, 3rd and 4th field from a file aaa.log
and producing output as
- sqlplus -sl dbsnmp/Or8cle@\"COL3:COL4/COL2\"
Input:
$ cat aaa.log aaa:fDb:a0081:1800:f1:dsds aaa:iDb:a0081:1801:i1:dsds aaa:pDb:a0081:1802:p1:dsds
Expected Output:
sqlplus -sl dbsnmp/Or8cle@\"a0081:1800/fDb\" sqlplus -sl dbsnmp/Or8cle@\"a0081:1801/iDb\" sqlplus -sl dbsnmp/Or8cle@\"a0081:1802/pDb\"
I extracted COL2 into a file:
$ cat aaa.log | cut -d":" -f2 > aaa_i.log $ cat aaa_i.log fDb iDb pDb
and extracted COL3 and COL4:
$ cat aaa.log | awk -F: '{print $3 ":" $4}' > aaa_h_p.log $ cat aaa_h_p.log a0081:1800 a0081:1801 a0081:1802
I tried using the below code.
set -f IFS=' > ' set -- $( cat aaa_i.log) for i in `cat aaa_h_p.log` do printf "%s %s\n" "sqlplus -sl sys/hSys10Nov@\""${i}"/"$1"\"" done
Current Ouput:
sqlplus -sl dbsnmp/Or8cle@\"a0081:1800/fDb\" sqlplus -sl dbsnmp/Or8cle@\"a0081:1801/fDb\" sqlplus -sl dbsnmp/Or8cle@\"a0081:1802/fDb\"
I am getting only fDb in COL2 in the o/p, whereas I want all the values there. Please help me correct the code. Even changes using AWK are welcome.
for
loop; zsh supports at least two, if not more. (I've never needed to use more than two.)`
) are discouraged: use$(...)
instead. see: Bash Hackers for more information.echo aaa:fDb:a0081:1800:f1:dsds | awk -F ':' '{printf("%s\n", "sqlplus -sl dbsnmp/Or8cle@\"$3:$4/$2\""); }'