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

From wiki
Jump to navigation Jump to search
Line 4: Line 4:
  
 
==head tail==
 
==head tail==
 +
 +
Show only top or trailing line from a file
 +
;tail <num> filename
 +
:Show the last <num> lines from filename. 10 is the default
 +
;head -<num> filename
 +
:Show the first <num> lines from filename. 10 is the default
 +
;tail +<num> filename
 +
:Show all lines from line <num> onwards
 +
 +
;tail +<lineno> filename|head -<num>
 +
:show <num> lines starting at <lineno>
  
 
==fold==
 
==fold==

Revision as of 10:22, 28 July 2020


cat

head tail

Show only top or trailing line from a file

tail <num> filename
Show the last <num> lines from filename. 10 is the default
head -<num> filename
Show the first <num> lines from filename. 10 is the default
tail +<num> filename
Show all lines from line <num> onwards
tail +<lineno> filename|head -<num>
show <num> lines starting at <lineno>

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