从csv等格式的数据中查询、导出、合并

2024-06-10 13:26:00 浏览数 (1)

1. grep

grep is a powerful tool for query some pattern in a file.

grep is short for global regular expression print.

1.1 syntax

代码语言:linux复制
grep [OPTION...] PATTERNS [FILE...] > [NEW FILE...]  
# > new file:存为new file,如果是已有文件名,将覆盖。    
# >> old file:追加到旧文件尾部。

1.2 options:

-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. 计数行数

2. head

head prints the first lines of one or more files (or piped data) to standard output.

2.1 syntax

代码语言:linux复制
head [option] file_name

2.2 options

-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,

代码语言:linx复制
head -1 [options] file1.txt > file2.txt #把file1的第一行存为file2.txt。 

3. cat

cat is short for concatenate. 连接

3.1 syntax

代码语言:linux复制
cat [options] [file_name]

example,

代码语言:linux复制
cat file1.txt file2.txt > file3.txt  #将file1和file2合并,file1在前,存为file3.

3.2 options

-n Creates a numbered list with all lines, including blank lines.

0 人点赞