-1

我在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

感谢您的帮助!

4

3 回答 3

1

我怎样才能把这三行写成一个脚本?

通过学习awk!最好的起点是阅读Effective Awk Programming

于 2013-08-28T19:12:54.123 回答
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)
于 2013-08-28T19:12:37.900 回答
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
于 2013-08-28T19:12:18.897 回答