grep is a powerful tool for query some pattern in a file.
grep is short for global regular expression print.
grep [OPTION...] PATTERNS [FILE...] > [NEW FILE...]
# > new file:存为new file,如果是已有文件名,将覆盖。
# >> old file:追加到旧文件尾部。
-i, --ignore-case: Ignores case distinctions in patterns and input data.忽略大小写
-v, --invert-match: Selects the non-matching lines of the provided input patterns.反向筛选
-n, --line-number: Prefix each line of the matching output with the line number in the input file.显示行号
-w: Find the exact matching word from the input file or string. 精确查找
-c: Count the number of occurrences of the provided pattern. 计数行数
head prints the first lines of one or more files (or piped data) to standard output.
head [option] file_name
-n --lines show the specified number of lines
-c --bytes show the specified number of bytes
-v --verbose show the file name tag,to display the file name before outputting the first 10 lines
-q --quiet don't separate the content of multiple files with a file name tag
example,
head -1 [options] file1.txt > file2.txt #把file1的第一行存为file2.txt。
cat is short for concatenate. 连接
cat [options] [file_name]
example,
cat file1.txt file2.txt > file3.txt #将file1和file2合并,file1在前,存为file3.
-n Creates a numbered list with all lines, including blank lines.
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。