Today to introduce several commonly used text processing commands and vim text editor
day3-- common text processing commands and text editors vim
col, used to filter control characters, -b filter out all control characters , and this command is not used, but you can use the name of the man command | col -b> help.txt
Exporting a help document. | Character is a pipe, for the preceding execution result via a "pipeline" to the rear
man ls | Help documentation col -b> ls_help # ls command to export
The cut command line cut off from each byte, and written to standard output
Cut - B # bytes divided Cut -b " l, 3 " # output of the first and third bytes Cut - C # character is divided in units of Cut -d # define separator, and need - F used with Cut -f -d use with #, output fields
cut -output-delimiter = 'delimiter' delimiter # replace their delimiter
wc statistics command
WC - C # shows the number of bytes WC - L line number # WC - W # Display Word Count
Exercise: use the pipe wc statistics order and cut command to count the number of characters in a file, and print to the screen
echo command output
echo -n output does not wrap #
head -n, n rows before viewing the file, the default 10 lines
tail -n, n line after viewing the file, the default 10 lines
Exercise: head and tail with the pipeline at the output / var / log / message content countdown line 10-15
cat view the file information
more appear as one page of the file information, the space is next, b button will display a back
less, use less free to browse files
sort sort
the Sort - b # ignore whitespace characters per line starting with the Sort - c # to check whether the file is sorted from the Sort - f # lowercase letters as uppercase letters the Sort - O output file # will result into the specified file the Sort -r # in reverse sort order
sort -n # sorted according to the size of numerical
sort -t separator delimiter designated #
Example:
removing duplicate rows uniq
Examples :( previous numbers indicate total there have been several)
当重复的行不相邻时,uniq是不起作用的,于是需要配合sort来使用去除重复的行
练习:使用uniq,sort来去除不相邻重复的行
tr命令对标准输入的字符进行替换
echo "hello,fissure" | tr 'a-z' 'A-Z' #将小写转化为大写
vim文本编辑器
vim是一个方便的编辑器,对于程序开发,脚本的编写来说是一把利器。
vim分为三种模式:命令模式,输入模式,底边模式
最小安装是没有vim这个包的,我们需要安装
sudo apt-get install vim-gtk #Ubuntu yum install vim -y #CentOS
安装成功后,我们输入命令 vim day03.txt
此时我们就进入了命令模式,此状态下无法输入,可以为vim传递命令,a或i切换到输入模式
我们在命令模式下敲冒号:,就进入了底边模式,底边模式下q为退出程序,w为保存文件,wq退出程序,以上命令后面加感叹号!代表强制执行
vim命令模式下常用快捷键
Ctrl+f 屏幕向下移动一页
Ctrl+b 屏幕向上移动一页
home或0 移动到一行最前面的字符
end或$ 移动到这一行最后面的字符
G 移动到最后一行
gg 移动到第一行
数字+G 移动到第几行
数字 向下移动几行
/string 查找string字符串
yy 复制当前行
dd 删除当前行
u 复原上一个动作
p 从下一行开始粘贴
P 从上一行开始粘贴