(. 1.): s/vivian/sky/Replace the current line the first Vivian is sky
: S/vivian/sky/g replaces the current line all Vivian are sky
(. 2.): N, $s/vivian/sky/the first Vivian of each row in the beginning of line N to the last row is sky
: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky
(n is a number, if N is., representing the beginning of the current line to the last row)
(. 3.):%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky
:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky
(. 4.) You can use # as a delimiter, at which time the middle appears/does not act as a delimiter
: s#vivian/#sky/# Replace the current row the first vivian/is sky/
(. 5.) Delete ^m in text
Problem description: For line breaks, the window is replaced by a carriage return (0a0d) to indicate that Linux is a carriage return (0A) to indicate § So, the window on the file on Unix, there will always be a ^ M. Please write a shell or C program that uses a newline character (0D) to filter Windows files under Unix
§ Using commands: Cat filename1 | tr-d "^v^m" > NewFile;
§ Use command: sed-e "s/^v^m//" filename >outputfilename. Note that in 1, 22 methods, ^v and ^m refer to Ctrl + V and ctrl+m. You have to do the input manually instead of pasting §
§ in VI Processing: First use VI to open the file, and then press the ESC key, followed by the command:%s/^v^m//.
§:%s/^m$//g
If the above method is useless, the correct solution is:
§tr-d \ "\\r\" < src>dest
§tr-d \ "\\015\" dest
§strings a>b
(. 6.) Other
Use the: s command to implement a string substitution § specific usage includes:
: s/str1/str2/replaces the first occurrence of a string in a line with a string str2 str1
: S/str1/str2/g replaces all occurrences of strings in a line with a string str2 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 replaces all occurrences of strings in the body with a string str2 str1
: g/str1/s//str2/g function Ibid.
Vim is used in conjunction with SED