text processing
cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt Merges the detailed description text of a file and writes the description to a new file
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt Combines the detailed description text of a file and writes the description to an existing file
grep Aug /var/log/messages finds the keyword "Aug" in the file '/var/log/messages'
grep ^Aug /var/log/messages finds words starting with "Aug" in file '/var/log/messages'
grep [0-9] /var/log/messages selects all lines containing numbers in the '/var/log/messages' file
grep Aug -R /var/log/* searches for the string "Aug" in the directory '/var/log' and subsequent directories
sed 's/stringa1/stringa2/g' example.txt replaces "string1" with "string2" in the example.txt file
sed '/^$/d' example.txt removes all blank lines from example.txt file
sed '/ *#/d; /^$/d' example.txt removes all comments and blank lines from the example.txt file
echo 'esempio' | tr '[:lower:]' '[:upper:]' merge the contents of the upper and lower cells
sed -e '1d' result.txt exclude first line from file example.txt
sed -n '/stringa1/p' see lines containing only the word "string1"
sed -e 's/ *$//' example.txt removes the last whitespace character on each line
sed -e 's/stringa1//g' example.txt removes only the word "string1" from the document and keeps the rest
sed -n '1,5p;5q' example.txt view the content from the first line to the fifth line
sed -n '5p;5q' example.txt see line 5
sed -e 's/00*/0/g' example.txt replaces multiple zeros with a single zero
cat -n file1 indicates the number of lines in the file
cat example.txt | awk 'NR%2==1' deletes all even lines in the example.txt file
echo abc | awk '{print $1}' to view the first column of a line
echo abc | awk '{print $1,$3}' to see the first and third columns of a line
paste file1 file2 merge the contents of two files or two columns
paste -d '+' file1 file2 合并两个文件或两栏的内容,中间用"+"区分
sort file1 file2 排序两个文件的内容
sort file1 file2 | uniq 取出两个文件的并集(重复的行只保留一份)
sort file1 file2 | uniq -u 删除交集,留下其他的行
sort file1 file2 | uniq -d 取出两个文件的交集(只留下同时存在于两个文件中的文件)
comm -1 file1 file2 比较两个文件的内容只删除 'file1' 所包含的内容
comm -2 file1 file2 比较两个文件的内容只删除 'file2' 所包含的内容
comm -3 file1 file2 比较两个文件的内容只删除两个文件共有的部分