How to manage file through awk?

2019-06-11 22:13发布

I have file which contain code below like

"H","@100",8002,"LLOYDSPHARMACY","Clonskeagh Dublin 14 Tel: 2697086","SCRIPT",20150226  (This is header line)
"M","backdata","1"
"D","GMA",20130101,,0,660C3BA9-E1C0-461B-840B-EDB1670865EA,47211482-AB66-41EE-9907-38B0C72CE497,,"F" (row)
"D","GMB",20130101,,0,660C3BA9-E1C0-461B-840B-EDB1670865EB,47211482-AB66-41EE-9907-38B0C72CE497,,"F" (row)

I want output below like same thing I did with cut command it is take so much time I want do only through awk.

Output file like this

8002(header)|LLOYDSPHARMACY(header) |660C3BA9-E1C0-461B-840B-EDB1670865EA(Column)|"F"(Column)|"GMA"(Column)
8002(header)|LLOYDSPHARMACY(header) |660C3BA9-E1C0-461B-840B-EDB1670865EB(Column)|"F"(Column)|"GMB"(Column) 

demo:-

    filename=test.txt
    sed -e '1,2d'  $filename > CUT_FILE

    f_1=`cat $filename | cut -d ',' -f3 | head -1`
    f_2=`cat $filename | cut -d ',' -f4 | head -1`

    f_3=`cat CUT_FILE | cut -d ',' -f9`
    f_4=`cat CUT_FILE | cut -d ',' -f2`

echo "$f_1|$f_2|$f_3|$f_4" > test

Please help me.

标签: shell awk
0条回答
登录 后发表回答