我在awk中找到了一个衬垫。我如何将这三行写成一个脚本?
awk -F":|," 'FNR==NR && /INFO - AId:/ {a[$6$8]=$0;next} END {for (i in a) print i "|" a[i]}' log >t1
awk '/<?xml version/ {f=1} /<\/iSig>/ {f=0;print $0 "\n" } f' log >t2
awk -F\| 'FNR==NR {a[$1]=$2;next} FNR==1 {RS="\n\n"} { for (i in a) {if ($0~i) {print a[i] $0 > i".log";close(i".log")}}}' t1 t2
感谢您的帮助!
答案 0 :(得分:1)
如何将这三行写入脚本?
通过学习awk
!最好的起点是阅读 Effective Awk Programming 。
答案 1 :(得分:0)
$ cat > myscript.sh <<EOF
#!/bin/sh
awk -F":|," 'FNR==NR && /INFO - AId:/ {a[$6$8]=$0;next} END {for (i in a) print i "|" a[i]}' log > $1
awk '/<?xml version/ {f=1} /<\/iSig>/ {f=0;print $0 "\n" } f' log >$2
awk -F\| 'FNR==NR {a[$1]=$2;next} FNR==1 {RS="\n\n"} { for (i in a) {if ($0~i) {print a[i] $0 > i".log";close(i".log")}}}' $1 $2
EOF
$ chmod +x myscript.sh
$ ./myscript.sh file1 file2
答案 2 :(得分:0)
首先作为bash你可以这样做:
awk -F\| 'FNR==NR {a[$1]=$2;next} FNR==1 {RS="\n\n"} { for (i in a) {if ($0~i) {print a[i] $0 > i".log";close(i".log")}}}' <(awk -F":|," 'FNR==NR && /INFO - AId:/ {a[$6$8]=$0;next} END {for (i in a) print i "|" a[i]}' log) <(awk '/<?xml version/ {f=1} /<\/iSig>/ {f=0;print $0 "\n" } f' log)