Search and replace under Linux

Source: Internet
Author: User
As an example, find the string "password" grep "password" in the. c file in the current directory *.c find the file Test.cfind in the current directory and its subdirectories. -name "TEST.c"-print find the. vbs file in the current directory and its multiple subdirectories and delete it. -name "*.vbs"-exec rm {} \; finds the string "password" find in the. c file of the current directory and its subdirectories. -name "*.C"-print | xargs grep "Password" replaces the string "password" in the. c file in the current directory with "pwd" Perl-pi-e ' s/password/pwd/g ' *.c the string "password" in the. c file in the current directory. Replace the "PWD" with the. bak extension to backup perl-pi.bak-e ' s/password/pwd/g ' *.c in the current directory and subdirectories in the. c file, replace the string "password" to "pwd" find. -name "*.C"-print | Xargs perl-pi-e ' s/password/pwd/g ' uses the Find-and-replace method in VI by using the: s command to implement a string substitution. Specific usages include: s/str1/str2/The first occurrence of a string in the replacement row with a string str2 str1:s/str1/str2/g the string str2 Replace all occurrences of the string in the row str1:., $ s/str1/str2/g with string str2 Replaces all occurrences of the current line to the end of the string str1:1,$ s/str1/str2/g with the string str2 Replace all occurrences of the string in the body str1:g/str1/s//str2/g function as seen above from the Replace command above: G at the end of the command, indicating the search Each occurrence of the string is replaced with no g, which means that only the first occurrence of the search string is replaced; G at the beginning of the command represents the substitution of all rows in the body that contain the search string.

Search and replace under Linux

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.