Text processing and searching commands

Text processing and searching commands.
=======================================================================
1> more : page wise view of text. this is old command and give only down scrolling.
#more filename

=======================================================================
2> less : It also provide page wise view. But give both up and down scrolling. Press space bar for next page and “Q” for quit.
#less filename

=======================================================================
3> head : show top 10 lines by default.
#head filename

you can pass cound line to show
#head -20 finename

=======================================================================
4> tail : be default it show 10 lines from bottom.
#tail filename

pass line cound
#tail -N fielname

growing file to check logs
#tail -f filename Or #tailf filename.

=======================================================================
5> grep : it search for require pattent in file

#grep “word” filename

#grep –color : show color to matching word

#grep -i : case insensitive.

#grep -v : show non matching patern.

#grep -n : show line number infront of matching lines.

#grep -m ‘No’ : show only N number of matching lines.

#grep -l ‘word” : list the files having matching patern.
=======================================================================

6> locate : it used to fine file by name. it maintain database of all the file/folders path.
#locate filename

extra : install mlocate package if command not found.
#updatdb : to update the related database

=======================================================================
7> look : search the linux inbuild dictionaly for given word/pattern.
#look ‘abc’

=======================================================================
8> apropos : it search the command having matching keyword/pattern.

=======================================================================
9> find : it used to searching file using name

#find path -name filename

i>search using size
#find / -size 10k

ii>search using permission
#find / -perm 644

iii>search using username
#find / -user username

iv>search using time

last access before “n” minutes ago
#find / -amin 2

last access before n*24 hours ago ( days ago)
#find / -atime 2
__________________________________________________
file status was last changes n minutes ago
#find / -cmin 2

file status changed before n*24 hours ago
#find / -ctime 2
____________________________________________________
file data was modified before n minutes ago
#find / -mmin 2

file data was modified before n*24 hours ago
#find / -mtime 2

=======================================================================
10> tr : translate upper to lower and lower to upper case.
#tr ‘a-z’ ‘A-Z’ < filename
=======================================================================

11> wc : word cound.

#wc filename

#wc -l filename : show line cound only

#wc -w filename : word cound only

#wc -m filename : charactor cound only.

=======================================================================
12> sort : sort the content of file alpha numerically.

#sort filename : accending order.

#sort -r filename : descending order

#sort -u filname : unique / remove duplicate lines.

=======================================================================
13> diff : compare files
#diff file1 file2

No output : both files are same
a : add line
c : line change

#diff3 file1 file2 file3 : compare 3 files

compare folder as per its content.
#diff folder1 folder2

=======================================================================
14> cut : used to peak up give number of character/field from given file. By default field separator is tab.

i> cut field
#cut -f 1,3 filename

ii> cut character
#cut -c 1,3 filename

iii> cut when have different delimeter ( separator)
#cut -d’:’ -f 1,3 filename

=======================================================================
15> awk : cut word/ column

#awk ‘{print $1}’ filename

=======================================================================

16> sed : search and replace

i> search and replace :
#sed ‘s/old/new/’ filename
Or
#sed ‘1,$ s/old/new/’ filename

Note : by default it replace all the matching word.

ii> replace specifice count only.
eg. one match
#sed ‘1 s/old/new/’ filename

iii> append word to match
#sed ‘s/old/& newwords/’ filename

iv>delete line
#sed ‘4d’ filename

v> delete empty / blank lines
#sed ‘/^&/d’ filename
=======================================================================

Posted in commands

Leave a Reply