Difference between revisions of "Linux/Unix:Find and Replace"

From wiki
Jump to navigation Jump to search
(Created page with "==cat== ==head tail== ==fold== ==strings== ==more less== ==tr== ;tr "[:upper:]" "[:lower:]" ;tr "[abc]" "[xyz]" :Transtlate, make all lowercase :replace all a's with y,...")
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Linux/Unix]]
 +
 
==cat==
 
==cat==
  
Line 11: Line 13:
  
 
==tr==
 
==tr==
;tr "[:upper:]" "[:lower:]"
+
;tr <nowiki>"[:upper:]" "[:lower:]"</nowiki>
;tr "[abc]" "[xyz]"
+
;tr <nowiki>"[abc]" "[xyz]"</nowiki>
 
:Transtlate, make all lowercase
 
:Transtlate, make all lowercase
 
:replace all a's with y, all b's with y and all c's with z, works from stdin to stdout. All sort of translations can be done
 
:replace all a's with y, all b's with y and all c's with z, works from stdin to stdout. All sort of translations can be done
Line 22: Line 24:
  
 
==sed==
 
==sed==
 +
 +
;s/pattern/newstring/
 +
:In each line replace first occurrence of pattern with newstring. /g at the end replaces all occurrences of pattern.
 +
 +
;s/pattern/d
 +
:Delete each line matching pattern.
  
 
==awk==
 
==awk==
  
 
==read==
 
==read==

Revision as of 08:33, 22 May 2019


cat

head tail

fold

strings

more less

tr

tr "[:upper:]" "[:lower:]"
tr "[abc]" "[xyz]"
Transtlate, make all lowercase
replace all a's with y, all b's with y and all c's with z, works from stdin to stdout. All sort of translations can be done
tr -d <char>
Delete <char> from standard input

grep

sed

s/pattern/newstring/
In each line replace first occurrence of pattern with newstring. /g at the end replaces all occurrences of pattern.
s/pattern/d
Delete each line matching pattern.

awk

read