- # text processing:
- # convert characters from lower to upper case:
fortune | tr [:upper:] [:lower:]
- # finding out how many times a particular item, in this case a dot, occurs on a text line
for a in `cat /tmp/file.txt`; do nof=$[`echo $a|sed s/'\.'/'\n'/g|wc -l` -1] echo a . occurs $nof times in $a done
- # unescaping escaped text/html/javascript/... found in a file $LOGFILE:
cat $LOGFILE|sed s/+/' '/g|sed s/%0D%0A/" -- "/g|sed s/%20/" "/g|sed s/%21/'!'/g|\ sed s/%22/'"'/g|sed s/%23/'\#'/g|sed s/%24/"$"/g|sed s/%25/"%"/g|sed s/%26/"\&"/g|sed s/%27/"'"/g|\ sed s/%28/'('/g|sed s/%29/')'/g|sed s/%2A/'*'/g|sed s/%2B/'+'/g|sed s/%2C/','/g|sed s/%2D/'-'/g|\ sed s/%2E/'.'/g|sed s/%2F/'\/'/g|sed s/%3A/':'/g|sed s/%3B/';'/g|sed s/%3C/'<'/g|sed s/%3D/'='/g|\ sed s/%3E/'>'/g|sed s/%3F/'?'/g|sed s/%40/'@'/g|sed s/%5B/'['/g|sed s/%5C/'\\'/g|sed s/%5D/']'/g|\ sed s/%5E/'^'/g|sed s/%5F/'_'/g|sed s/%60/'`'/g|sed s/%7B/'{'/g|sed s/%7C/'|'/g|sed s/%7D/'}'/g|\ sed s/%7E/'~'/g|sed s/%D3/'<'/g
- # a very nice overview of commonly used text processing commands can be found at http://www.tldp.org/LDP/abs/html/textproc.html
- # remove all blank lines from a file:
grep -v '^$' input.txt > output.txt
- # count the number of newlines, words and bytes in a text file:
wc input.txt
- # reverse all the lines in a file:
rev file.txt
- # convert characters from lower to upper case:
- # file processing:
- # dog is an enhancement of cat
- # count the number of times a particular character (in the example a comma) occurs in some file:
cat file.txt | tr -c -d ',' | wc -c
- # character set translator -- translates character sets from one encoding to another (utf-8, ascii, iso 8859-[123456789], unicode, msdos,...):
tcs
- # make a hexdump or do the reverse:
xxd file > file.hex xxd -r file.hex > file.bis
- # dump a file byte per byte using octet, decimal, hex or binary notation:
od -j 2 -t x1 file > file.hex
- # replace all spaces in all relevant file names by underscores:
find . -name \*' '\* -exec rename s/' '/_/g "{}" \;
- # strip the path from a filename, or the last part of an absolute path:
basename extendedFilename; dirname extendedFilename
- # find all files that are between 100 and 50 days old:
find . -mtime +50 -mtime -100 -daystart
- # process processing:
- # redirect stderr to stdout:
buggyProg 2>&1
- # redirect stdout to stderr:
buggyProg 1>&2
- # redirect both stderr and stdout to a file:
buggyProg &> file
- # redirect stderr to stdout: