7 Oct 2012

Text Processing Unix Commands

Text Processing Unix Commands

Text Processing Unix Commands

paste COMMAND IN UNIX
$ paste file1 file2 -> combines contents of both files line by line and displays
The '$ paste' command, it will combines file1 and file2 line by line and display on the console.


head UNIX COMMANDS
$ head file1 -> dispays 1st 10 lines of 'file1'
$ head -2 file1 -> displays 1st 2 lines of 'file1'
$ head -2 file1 file2 -> displays 1st 2 lines of 'file1' and 'file2'

head unix command use with ls commad.
$ ls -l -> It will long list all file present in current directory
$ ls -l|head -5 -> It will long list first five files.
That is 'ls -l' output will be input for 'head -5' (pipe '|' is for joining more then one commands.)


tail UNIX COMMANDS
$ tail file1 -> displays last 10 lines of 'file1'
$ tail -3 file1 -> displays last 3 lines of 'file1'
$ tail +3 file1 -> displays all lines from line 3

tail unix command use with ls commad.
$ ls -l -> It will long list all file present in current directory
$ ls -l|tail -5 -> It will long list last five files.
That is 'ls -l' output will be input for 'tail -5' (pipe '|' is for joining more then one commands.)


wc WORD COUNT UNIX COMMANDS
$ wc file1 -> prints no of lines, words and characters in 'file1'
$ wc -l file1 -> prints no of lines in 'file1'
$ wc -w file1 -> prints no of words in 'file1'
$ wc -c file1 -> prints no of characters(includes 'enter button') in 'file1'


cut UNIX COMMANDS
$ cut -c2 file1 -> displays only 2nd character of each line in 'file1'
$ cut -c2-6 file1 -> displays only characters 2-6 of each line in 'file1'
$ cut -d " " -f4 file2 -> displays only field 4 with delimiter " " in 'file2'
$ cut -d " " -file2,4 file2 -> displays fields 2 and 4
$ cut -d " " -file2-6 file2 -> displays fields 2 to 6


sort UNIX COMMANDS
$ sort file1 -> does alphabetical sorting
$ sort -r file1 -> does reverse sorting
$ sort -n file1 -> does numerical sorting
$ sort -u file1 -> removes duplicate data and sorts
$ sort -m file1 file2 -> merges 'file1' and 'file2' (works on sorted files)
$ sort -m file1 file2 -o op -> stores merged data in a file 'op'
$ sort +1 -t ":" file1 -> sorts on 2nd field(delimiter":") in 'file1' field no starts from 0



For any clarification with respect above commands reach me on by comments.

NOTE : All unix commands are case sensitive.

No comments:

Post a Comment