One question per day--5 awk advanced

Source: Internet
Author: User

每周绝望原数据文件:id=aa&bb&type&name=ccbb&id=aa&name=cc&typeid=aa&type&bb&name=ddtype&id=aa&cc&name=bbid=bb&cc&type&name=bbaa&id=bb&name=bb&type

Organize and go heavy, get the effect:

id=aa&bb&name=cc&typeid=aa&bb&name=dd&typeid=aa&cc&name=bb&typeid=bb&cc&name=bb&typeid=bb&aa&name=bb&type

Tip: awk loops, judgments, variable assignments, de-weighting mechanisms

First Milestone

awk -F ‘&‘ -v OFS=‘&‘ ‘{for(i=1;i<=4;i++)printf"%s" $i;printf "\n"}‘ awk.txt   实现每个遍历了awk -F ‘&‘ -v OFS=‘&‘ ‘{for(i=1;i<=4;i++){if($i~/^id.*$/)A=$i;if($i~/^[a-z]{2}$/)B=$i;if($i~/^name.*/)C=$i;if($i~/^type$/)D=$i}print A,B,C,D}‘ awk.txtecho {a..z} | xargs -n 1 >awk.txt

Use awk to remove the upper and lower 5 rows of the G row

for j in `awk ‘/^j$/{for(i=NR-5;i<=NR+5;i++)print i}‘ 1.txt `;do awk -v j=$j ‘NR==j{print $0}‘ 1.txt;done

One question per day--5 awk advanced

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.