Sed awk notes (ii)

Source: Internet
Author: User

All said that the SED awk maintenance personnel's necessary tools, starting today to organize related notes, first of all to meet these two things.

Commonality: Using the same syntax [Address]/pattern/action/flag

is a character stream-oriented, read input from a bank at a time, and output to standard output, which is input-driven

are pattern-matching using regular expressions.

Allows the user to specify instructions in the script

So the individual thinks there are several aspects that need to break through: grammar, regularization, scripting ideas

[[email protected] test] #今天写的脚本显示洲及所在州的人名

#! /bin/sh

Awk-f "," ' {print $4 ', ' $} ' $* | Sort |

Awk-f "," '

$ = = LastState {print "\t\t"

$ = laststate {LastState = $1;print $1;print "\t\t" $} '


List file

John daggett,341 King Road,plymouth MA

Alice ford,22 East Broadway,richmond VA

Terry kalkas,402 Lans road,beaver Falls PA

Amy wilde,334 Bayshore Pkwy,mountain View CA

Eric adans,20 Post Road,sudbury MA

Sal carpenter,73 6th Street,boston MA


SEDSCR Processing files

s/mq/, mqwwqdhuw355w/

s/ma/, mmmmmmmmmmmm/

s/pa/, penccccccccccc/

s/ca/, california/

s/va/, virginia/

s/ok/, oklahoma/

Command Sed-f SEDSCR | Bystate output

California

Amy Wilde

Mmmmmmmmmmmm

Eric Adans

John Daggett

Sal Carpenter

Penccccccccccc

Terry Kalkas

Virginia

Alice Ford

This place has a program that is how to write your own shell programming executable

chmod +x bystate Grant Execute permission

./bystate or bash bystate execution

If prompted Bystate is not an executable program export path= $PATH:/home/test #my bystate in/home/test/


This article from "Yun Weibang" blog, declined reprint!

Sed awk notes (ii)

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.