๐ Paste Command in Linux with Examples
๐ Cut Command in Linux with Examples
$ grep "error" system_logs.txt๐ Explanation:
This command searches for the word "error" in the file system_logs.txt and displays the matching lines.
๐ฏ Output (Example):
2024-12-28 10:22:30 Error: File not found
2024-12-28 11:01:02 Error: Permission denied
2024-12-29 14:10:05 Error: Out of memory$ grep -E "^2024-12-28" system_logs.txt๐ Explanation:
This command displays only those lines from system_logs.txt that start with 2024-12-28. Here, -E enables regular expressions.
๐ฏ Output (Example):
2024-12-28 10:22:30 Error: File not found
2024-12-28 11:01:02 Error: Permission denied$ cut -d ',' -f 1,3 employees.csv๐ Explanation:
-d ','โ Defines comma (,) as the delimiter.-f 1,3โ Extracts 1st and 3rd columns fromemployees.csv.
๐ฏ Output (Example):
John, Developer
Alice, Manager
Bob, Tester$ cut -d ' ' -f 2,4 data.txt๐ Explanation:
This command extracts 2nd and 4th columns from data.txt, using space as the delimiter.
๐ฏ Output (Example):
Developer, New York
Manager, California
Tester, Texas$ paste file1.txt file2.txt๐ Explanation:
This command joins the contents of file1.txt and file2.txt side-by-side, separating columns with a tab (\t).
๐ฏ Output (Example):
Line 1 from file1 Line 1 from file2
Line 2 from file1 Line 2 from file2
Line 3 from file1 Line 3 from file2$ paste -d '\t' column1.txt column2.txt๐ Explanation:
This command merges column1.txt and column2.txt using a tab (\t) as a separator.
๐ฏ Output (Example):
John Developer
Alice Manager
Bob Tester$ grep "error" system_logs.txt | cut -d ' ' -f 1,3 | paste -s -d ',' -๐ Explanation:
grep "error" system_logs.txtโ Searches for "error" insystem_logs.txt.cut -d ' ' -f 1,3โ Extracts 1st and 3rd columns (date and error type).paste -s -d ',' -โ Joins output into a single line, separated by commas.
๐ฏ Output (Example):
2024-12-28, Error
2024-12-29, Error$ paste file1.txt file2.txt | cut -d '\t' -f 1 | grep "important"๐ Explanation:
paste file1.txt file2.txtโ Mergesfile1.txtandfile2.txt.cut -d '\t' -f 1โ Extracts only the first column.grep "important"โ Filters lines containing"important".
๐ฏ Output (Example):
important log entry 1
important log entry 2$ grep "successful" server_logs.txt | cut -d ' ' -f 1,2 | paste -d ',' - results.txt๐ Explanation:
grep "successful" server_logs.txtโ Filters lines containing "successful".cut -d ' ' -f 1,2โ Extracts date and time columns.paste -d ',' - results.txtโ Merges filtered data withresults.txt, separating by commas.
๐ฏ Output (Example):
2024-12-28, 12:00:00, success
2024-12-28, 14:30:00, success