Using awk grep sed: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 6: | Line 6: | ||
== sed == | == sed == | ||
Things that you can accomplish using RegEx within the Vi editor on text files can also be accomplished at the command line with sed. | Things that you can accomplish using RegEx within the Vi editor on text files can also be accomplished at the command line with sed. | ||
== examples == | |||
=== process text file by removing blanks, unwanted lines, and duplicates === | |||
Get rid of all lines of text containing numerical stats | |||
sed -i '/[0-9]/d' Razor-Fen.txt | |||
Get rid of all empty lines containing no characters | |||
sed -i '/^\s*$/d' Razor-Fen.txt | |||
Get rid of all duplicate lines | |||
sed -i '$!N; /^\(.*\)\n\1$/!P; D' Razor-Fen.txt | |||
Revision as of 12:59, 14 January 2020
grep does not alter a file, it only finds matches while awk and sed are text processors.
awk is mostly used for data extraction and reporting. sed is a stream editor Each one of them has its own functionality and specialties.
sed
Things that you can accomplish using RegEx within the Vi editor on text files can also be accomplished at the command line with sed.
examples
process text file by removing blanks, unwanted lines, and duplicates
Get rid of all lines of text containing numerical stats
sed -i '/[0-9]/d' Razor-Fen.txt
Get rid of all empty lines containing no characters
sed -i '/^\s*$/d' Razor-Fen.txt
Get rid of all duplicate lines
sed -i '$!N; /^\(.*\)\n\1$/!P; D' Razor-Fen.txt