1. Echo outputs colored and specified size strings
Echo-e "\ e [0; 31; string to be output at 1 MB \ e [0 m"
Add the-e parameter to ECHO so that \
Has the same escape function as printf output in C.
\ E [0; 31; 1 M indicates that the output character is set to Red 31 (no background color), and 1 m indicates that the output character is in bold.
More control functions are as follows:
Encoding color/Action
0. Reset the property to the default setting.
1. Set bold
2. Set half brightness (simulate color display)
4. Set the underline to simulate the color of the color display)
5. Set flashing.
7. Set reverse Images
22. Set the general density
24. Close the underline
25 turn off flashing
27 disable reverse image
30 set the black foreground
31 set the red foreground
32. Set the green foreground
33 set the brown foreground
34 set the blue foreground
35 set purple foreground
36 set the blue foreground
37 set the white foreground
38. Set the underline on the default foreground color
39. Disable the underline on the default foreground color
40 set a black background
41 set the red background
42 set a green background
43 set brown background
44 set the blue background
45 set a purple background
46 set the blue background
47 set the white background
49 set the default black background
Other interesting code:
\ 033 [2j clear screen
\ 033 [close all keyboard lights with 0q
\ 033 [1 Q: Set the "scroll lock" indicator (scroll lock)
\ 033 [set the "numerical lock" indicator (num lock) for 2q)
\ 033 [set "Caps Lock" for 3q)
\ 033 [15: 40 h move close to 15th rows, 40 Columns
\ 007 beep
2. String judgment
If (echo "this is string test! "| Grep-Q '^ [a-zA-Z0-9] \ + $'); then
Echo "Valid String input"
Else
Echo "illegal string input"
Fi
The above script will output "the string input is invalid" because the added condition is used to detect whether the string is only composed of a-Z or A-Z or 0-9 characters, the preceding string contains a space character.
If (echo "12my_project" | grep-Q '^ [A-Za-Z]');
Then
Echo "valid project name input"
Else
Echo "invalid project name input"
Fi
The above script will output "invalid project name input", because the added condition judgment is used to check whether the string starts with a letter
Pipeline Operation symbols | more
Http://blog.csdn.net/cnctloveyu/article/details/4131770
More about grep
Http://blog.csdn.net/deansrk/article/details/6628630
Positive expression
Http://zh.wikipedia.org/wiki/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F
3. Search for the specified content in the specified file and insert characters (Template)
(Echo "/panther_config/I"; echo-e "$ {new_project_name} _ config: unconfig \ n @. /mkconfig \ $ (@: _ Config =) arm omap3 $ {new_project_name} \ n "; echo '. ';
Echo 'wq') | ed makefile
The above script is used to search for the panther_config string in the MAKEFILE file and set the Template
$ {New_project_name} _ config: unconfig \ n @./mkconfig \ $ (@: _ Config =) arm omap3 $ {new_project_name} \ n
Insert it to the front of the searched string. This is used to automatically add a project to the makefile of xloader. The project name I added is new_project_name = zt6810, the above script will generate the following content in makefile:
Zt6810_config: unconfig
@./Mkconfig $ (@: _ Config =) arm omap3 zt6810
The Ed command is used here.
Http://biancheng.dnbcw.info/shell/242647.html
4. Batch replacement and case-sensitivity Conversion
Sed-I "s/zt6810/'echo $ new_project_name | tr [A-Z] [A-Z] '/g" include/configs/$ new_project_name.h
In the above script, note that the marked red part is the single quotation mark on the table key.
The preceding command can be split into two parts:
A. Convert uppercase and lowercase letters
Echo $ new_project_name | tr [A-Z] [A-Z]
This sentence converts all the lowercase letters in the variable new_project_name to uppercase. Note the space character between [A-Z] and [A-Z ].
B. Sed-I .....
Replace the character string zt6810 that has been converted to uppercase in.
Sed statements are frequently used:
Insert a new row after the first row of a file
Sed-I 'the row I \ content to be inserted 'file
Insert content after specified characters in a file
Sed's/specified characters/& characters to insert/'file
Replace the specified character
Sed-I's/specified character/character to be replaced/'file
Inserts a character into the row containing the specified character
Sed '/specified character/A \ character to be inserted' file
Linux Perl shell Perl VI grep awk xargs batch replacement
Method 1:Maven is used to build an application in the past two days. Due to the large project, there are more than 700 pom S. XML file, even more depressing is in many pom. the URL of the resource library is specified separately in the XML file. I need to uniformly specify the URLs of these resource libraries to the local central nexus library.
Manually changing the file configuration is a bit impractical, So Google, find a good way to replace the file content in batches, the command structure is as follows:
Find-name 'file name to be searched' | xargs Perl-pi-E's | replaced string | G' the following example shows the current directory and all all pom. & #8221;
Http://repo1.maven.org/maven2& #8220; Replace with & #8221;
Http: // localhost: 8081/nexus/content/groups/Public& Amp; #8220 ;.
Find-name 'pom. XML '| xargs Perl-pi-E's | http://repo1.maven.org/maven2 | http: // localhost: 8081/nexus/content/groups/Public | G' the Perl language is used here,
Perl-pi-E: add the-e option to the Perl Command, followed by a line of code. Then, it will run the code like running a common Perl script.
Using Perl from the command line can help implement some powerful and real-time conversions. Studying Regular Expressions carefully and using them correctly will save you a lot of manual editing work.
Find-name 'pom. xml' | xargs Perl-pi-E's | http://repo1.maven.org/maven2 | http: // localhost: 8081/nexus/content/groups/Public | G'
Method 2:
A simple method to replace strings in multiple files in batches in Linux. You can use the SED command to replace strings in multiple files in batches.
You can use the SED command to replace strings in multiple files in batches.
Sed-I "s/original string/New String/g" 'grep original string-rl directory'
For example, to replace mahuinan with huinanma, run the following command:
Sed-I "s/mahuinan/huinanma/g" 'grep mahuinan-RL/WWW'
This is the simplest string replacement command in Linux!
The specific format is as follows:
Sed-I "s/oldstring/newstring/g" 'grep oldstring-RL/Path'
Instance code: sed-I "s/size/Sun/month/g" 'grep size-RL/usr/'
Sed-I "s/size/Sun/month/g" 'grep size-rl ./'
Method 3:
During the development of the schedule, you may encounter the situation of changing a variable name to another variable name. If this variable is a local variable, VI is sufficient, however, if a global variable is used in many files, using VI is an unwise choice. A simple shell command is provided here to modify the specified string in all files at a time:
Grep "ABC" *-r | awk-F: '{print $1}' | sort | uniq | xargs sed-I's/ABC/ABCDE/G'
From: http://blog.zol.com.cn/1395/article_1394052.html
Additional instructions:
Sed-I "s/oldstring/newstring/g" 'grep oldstring-RL/Path'
Processing of multiple files may not be supported.Xargs.
The variants are as follows:
Grep oldstring-RL/path | xargs sed-I "s/oldstring/newstring/G"
Note::
In 'grep oldstring-RL/path', 'is the quotation mark of the first side.`Instead of enter
Before'