Shell-05
sed command
Linux text processing Three Musketeers sed statement (line editing - flow editor stream editor)
As a line editor to edit the text, in units
Note: sed to edit the file, but do not change the original file;
Sed works:
In sed which will provide an address space, will appear in the linux memory in a model space PATTERN SPACE, read a line
Develop a text file, a text file in order to read the contents of each line, to read the pattern space (PATTERN SPACE), text matching (regular expression) in the pattern space, the contents of the match modify ( replace , delete, print, edit, save)
Sed usage:
sed [option] …{script-only-if-no-other-script} [input-file]
sed [parameters] ... "sed own independent use format statement" [Text File]
Common options:
-r specify extended regular expressions
Match IP address
1. All of \ Do not
2. | or
-n refused default output
But -n '1,2p' 99cfb.sh
-e script for while if
for i in {1..9};do echo “$i” sleep 1;done
-f script file specified
-L length specified text wrap
-i directly modify the contents of the file (do not use)
Sed address delimitation way of command
- Direct matching value
However -n '5,7p' 99cfb.sh
- digit for (number) to specify an increment step d ~
sed -n '1 ~ 3 / j / @ / p 99cfb.sh
- $ Specified Gyoo
Sed -n '10, $ p 'file
Sed -n '\ fd \, $ p' ----- file to match the last line from fd
- 0, addr --- addr can be a digital / $ / regular expression
- Sed -n ‘0,/k\{5,\}/p’ abc
- Sed -n ‘/\(as\)\+/,/\(ds,\)\+/p’ abc
- addr,+N
Addr line to the match, the lines addr N
Sed -n ‘/fd/,+5p’ abc
- addr,-N
sed -n ‘1,~3p’ abc
Common commands:
p print print the default display on the screen, used in conjunction with -n recommended
c Replace the line sed "/ aaa / c \ A" file name
d delete sed "/ aaa / d" to delete the file name to match the line
sed "1,3d" file name
n N Read / pattern matching is added to the contents of the next line in the line to manipulate
w Save the file contents to a new file
* S * replaces the default text contents of the first replacement pattern matching to the space
All g global / global
Syntax: intermediate s / pattern / string / replace any --- slash why a special character
\ 1 \ 2 \ 3 ... and the regular expression is the same packet to achieve reverse application
Designate a replacement to modify a match
- fourth row if the third for replacing
Fourth row if the third and for replacing the stored 99xfb.sed.sh
i add content matching row line
sed “/for/i abc ” filename
Add the contents of a matching line in the next line
sed “/for/a abc ” filename
Grip "testbash" / etc / passwd | Sed "s # ^ test. * # & Is # g"
E.g. s ###, s @@@, s %%%
sed “s/k/K/gw /root/aabbcc” abc
sed of advanced applications
D hold space- occupy space
random number
RANDOM range 0-32767
A=$[$RANDOM%100+1]
Exercise:
- cat /boot/grub/grub.conf sed ‘s/^[[:space:]]\+//g’ /boot/grub/grub.conf
- cat /etc/fstab sed ‘s/^#[[:space:]]\+//’ /etc/fstab
- echo “/var/log/message | ”sed ‘s/[^/]\+$//’
- echo "/var/log/message" | sed 's#^/.*/##'
-
Remove the file path dirname path portion ----
Remove the file path of the basename file portions ----
Endless loop
while true;do
Loop
done
break- break out of the loop
continue ---- out of this cycle
After prolonged sleep ---- how long to continue the cycle
until
And while the use of the same
Difference: only when the judgment condition is false, will enter the loop
Exercise 2:
#! / bin / bash CAT << EOF menu ============================ " the CPU) display cpu information " " Mem) displays memory information " " disk) disk information displays " " the quit) to exit the " ============================ EOF the while to true ; do the Read - the p- " Please enter the required view: " info echo "" IF [the -z $ info ]; the then echo " Please enter a correct parameters !! " echo "For example: the CPU Mem the Quit Disk " # exit 1 fi if [ $info = "cpu" ];then cat /proc/cpuinfo elif [ $info = "mem" ];then free -m elif [ $info = "disk" ];then fdisk -l elif [ $info = "quit" ];then echo "已退出" Exit 0 the else echo " input information is incorrect " echo " Please enter a valid argument! ! " Echo " For example: the CPU Mem Disk the Quit " Exit 2 Fi DONE
progress bar
Vim .vimrc
Some of the default parameter editing vim
Cloud Desktop
Role: to assign a PC client from the cloud, so that customers work in the cloud;
- Safety
- Convenience
[In vim, representative of the current line cursor ".": "., $ S / ^ / # / ----- from the cursor to the beginning of the current line end of the line is replaced by #"]
1 to 3, 1,4,7,11 step ----
/ Pattern1 /, / pattern2 ---- from pattern matching to the line, the pattern matching to the line 1 2
Digital, + N
/pattern1/,+N------".,+3s/^#// "at the beginning of the line to the last three rows displaced from the cursor into the air current