Shell tips modification Suffix and grep

Source: Internet
Author: User

Batch modify file suffix

The first type:

#!/bin/bashfor fn in *.$1domv $fn ${fn%$1}$2done

The second type:

Find. -name "*.txt" | Awk-f ' [./]+ ' {print $} ' | Xargs-i-T mv {}.txt {}.sh

GREP User Tips

The file is as follows:

# cat Test.txt This was a test Filea good day and no coludysit here and sing a Songmiss Agao istingbut money are money!this Is:hangonly one line.

-W matches entire word, avoids word character match

# grep-w is Test.txt-a test filebut money are money!this Is:hang

No match to Isting


-A matches N rows after

# grep-a 3 sit test.txt sit here and sing A Songmiss Agao istingbut money are money!this Is:hang


-B matches the previous n rows

# grep-b 2 Sit test.txt This was a test Filea good day and no coludysit here and sing a song


-C matches before and after n rows

# grep-c 2-i sit test.txt This was a test Filea good day and no coludysit here and sing a songmiss Agao istingbut money I S money!


-C Statistics Match line number:

# grep-c is test.txt 4

-O displays only matching strings:

# Grep-o Money Test.txt Moneymoney


-o-b shows the location of the match:

# Grep-o-B Sit test.txt 45:sit

Intersection and Difference sets:

# cat 1.txt 1234# cat 2.txt 123456

Intersection:

# grep-f 1.txt 2.txt 1234

Subtraction

# GREP-VF 1.txt 2.txt 56

This article is from the "OPS rookie" blog, please be sure to keep this source http://ckl893.blog.51cto.com/8827818/1766655

Shell tips modification Suffix and grep

Related Article

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.