Linux/Unix:Find and Replace: Difference between revisions
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,..." |
|||
| (11 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Linux/Unix]] | |||
==cat== | ==cat== | ||
==head tail== | ==head & tail== | ||
Show only top or bottom lines from a file | |||
;tail <num> filename | |||
:Show the last <num> lines from filename. 10 is the default | |||
;tail -f filename | |||
:Keep showing all files appended to the file | |||
;head -<num> filename | |||
:Show the first <num> lines from filename. 10 is the default | |||
;head -n -<num> filename | |||
:Show all except the last <num> lines from filename | |||
;tail -n +<num> filename | |||
:Show all lines from line <num> onwards | |||
;tail -n +<lineno> filename|head -<num> | |||
:show <num> lines starting at <lineno> | |||
==fold== | ==fold== | ||
==strings== | ==strings== | ||
;strings filename | |||
:Try to show the file content in printable characters | |||
==more less== | ==more less== | ||
| Line 11: | Line 30: | ||
==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 21: | Line 40: | ||
==grep== | ==grep== | ||
== | ==[[Sed]]== | ||
See the [[Sed]] page. | |||
;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]]== | ||
See the [[Awk]] page | |||
==read== | ==read== | ||
Latest revision as of 14:09, 15 November 2022
cat
head & tail
Show only top or bottom lines from a file
- tail <num> filename
- Show the last <num> lines from filename. 10 is the default
- tail -f filename
- Keep showing all files appended to the file
- head -<num> filename
- Show the first <num> lines from filename. 10 is the default
- head -n -<num> filename
- Show all except the last <num> lines from filename
- tail -n +<num> filename
- Show all lines from line <num> onwards
- tail -n +<lineno> filename|head -<num>
- show <num> lines starting at <lineno>
fold
strings
- strings filename
- Try to show the file content in printable characters
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
See the Sed page.
- 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
See the Awk page