-
sed: stream editor, best for search and replace and not much elseCOMMAND | sed "s/SEARCH_STRING/SUBSTITUTION_STRING/"replaces regex-defined string substitute in output
-
Both
sedandgrepsearch strings can use regular expressions, aka regex, to capture text that follows certain patterns- Use
sed -Eoption for normal regex syntax
- Use
-
Characters
\d= digit (0-9)\D= non-digit\w= alphanumeric\W= non-alphanumeric.= any character\s= any whitespace\S= non-whitespace\= escapes special char (.,*,[, etc.)
-
Other
^...$= line start and end()= capture group, content can be referred via\1,\2,\3, etc. in sequential order
-
Character classes
[abc]= a, b, or c[123]= 1, 2, or 3[^abc]= NOT a, b, or c[a-z],[0-9]= as expected
-
Quantifiers
*= 0 or more times+= 1 or more times?= 0 or 1 times{NUM}=NUMtimes{LOW,HIGH}=LOWtoHIGHtimes
-
Tutorial: https://regexone.com/
sort= take file content/input stream and sort ituniq= remove redundant lines, but only if adjacent, so pipe in fromsort= add-cto include countshead,tail= use with-n NUMto see the first/lastNUMlinesawk= print theNUMth column on each line withawk {print $NUM}- More functionality like
sed, rather complex though
- More functionality like
paste= combines file content/inputbc= command-line calculator, used likeecho "OPERATION" | bc -lxargs= takes a list of inputs and turns them into arguments, i.e.ARGS_SOURCE | xargs COMMAND- For specific use cases, remember to refer to documentation via
man,--help, ortldr jq= JSON parserpup= HTML parserpandas= Python library