Awk replacement matching awk replacement text content learning feels good [root @ localhosttest] # catawk1a9, 100.341b1, 999.001c5, 656.55 [root @ localhosttest] # awk & amp; #39; {sub (/1/, & quot; test & quot;)} {print & quot; \ n & quot; awk replacement matching
Awk replaces text content to learn [root @ localhost test] # cat awk
1a 9,100.34
1b 1,999.00
1c 5,656.55
[Root @ localhost test] # awk '{sub (/1/, "test")} {print "\ n", $1, $2}' awk
Testa 9,100.34
Testb 1,999.00.
Test C 5,656.55
[Root @ localhost test] # awk '{gsub (/1/, "test")} {print "\ n", $1, $2}' awk
Testa 9, test00.34
Testb test, 999.00
Test C 5,656.55
[Root @ localhost test] # awk '{sub (/[0-9] +/, "")} {print "\ n", $1, $2} 'awk
A 9,100.34
B 1,999.00
C 5,656.55 prints awk' $1 ~ with only four characters in $1 ~ /^ .... $/{Print $1} 'file: The learning result is Yes, but the time and system time cannot match [root @ localhost test] # cat awk
1 A 9,100.34 dkjfjkdkjf 45 lopo
1b 1,999.00 dgfg 456 ll
1c 5,656.55 fghgf 465 df [root @ localhost test] # awk '{$2 = strftime ("% F % T", $2); print $1, $2, $3> "bbb.txt"; print $1, $2, $4> "ccc.txt"} 'awk
[Root @ localhost test] # cat bbb.txt
1a 1969-12-31 16:00:09 dkjfjkdkjf
1b 1969-12-31 16:00:01 dgfg
1c 1969-12-31 16:00:05 fghgf
[Root @ localhost test] # date
Wed Dec 14 22:49:28 PST 2011
[Root @ localhost test] # cat ccc.txt
1a 1969-12-31 16:00:09 45
1b 1969-12-31 16:00:01 456
1c 1969-12-31 16:00:05 465 [root @ localhost test] # date
Wed Dec 14 23:07:09 PST 2011
The problem has been solved. remove $2 from {$2 = strftime ("% F % T", $2) to get the correct format. for details, see a file. the number of columns is different, if there are 5 columns, take the first 4 columns. if there are 6 columns, take the first 5 columns and print them when the first column is greater than 2.
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