|
Command Code
|
Description
|
|
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt
|
Merge detailed explanation text of a file and write the summary to a new file
|
|
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt
|
Merge detailed explanation text of a file and append the summary to an existing file
|
|
grep Aug /var/log/messages
|
Search for the keyword "Aug" in the file '/var/log/messages'
|
|
grep ^Aug /var/log/messages
|
Search for words that start with "Aug" in the file '/var/log/messages'
|
|
grep [0-9] /var/log/messages
|
Select all lines in the '/var/log/messages' file that contain numbers
|
|
grep Aug -R /var/log/*
|
Search for the string "Aug" in the '/var/log' directory and its subdirectories
|
|
sed 's/stringa1/stringa2/g' example.txt
|
Replace "string1" with "string2" in example.txt
|
|
sed '/^$/d' example.txt
|
Delete all blank lines from example.txt
|
|
sed '/ *#/d; /^$/d' example.txt
|
Delete all comments and blank lines from the file
|
|
echo 'example' | tr '[:lower:]' '[:upper:]'
|
Merge cell contents
|
|
sed -e '1d' result.txt
|
Exclude the first line from example.txt
|
|
sed -n '/stringa1/p'
|
View only lines that contain the word "string1"
|
|
sed -e 's/ *$//' example.txt
|
Remove trailing whitespace from each line
|
|
sed -e 's/stringa1//g' example.txt
|
Remove the word "string1" from the document and keep 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
|
View the fifth line
|
|
sed -e 's/00*/0/g' example.txt
|
Replace multiple zeros with a single zero
|
|
cat -n file1
|
Number the lines of the file
|
|
cat example.txt | awk 'NR%2==1'
|
Remove all even lines from example.txt
|
|
echo a b c | awk '{print $1}'
|
View the first column of a line
|
|
echo a b c | awk '{print $1,$3}'
|
View the first and third columns of a line
|
|
paste file1 file2
|
Combine the contents of two files or columns
|
|
paste -d '+' file1 file2
|
Combine the contents of two files or columns separated by a "+"
|
|
sort file1 file2
|
Sort the contents of two files
|
|
sort file1 file2 | uniq
|
Get the union of two files (duplicate lines retain only one)
|
|
sort file1 file2 | uniq -u
|
Remove the intersection, leaving the other lines
|
|
sort file1 file2 | uniq -d
|
Get the intersection of two files (only keep files that exist in both files)
|
|
comm -1 file1 file2
|
Compare the contents of two files and remove only content contained in 'file1'
|
|
comm -2 file1 file2
|
Compare the contents of two files and remove only content contained in 'file2'
|
|
comm -3 file1 file2
|
Compare the contents of two files and remove the common parts
|