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.

2 Oct 2012

File handling Unix commands

File handling in unix shell scripts

The following unix shell scripts commands for handling files like creating file, copying file, moving file and listing files.

CREATING FILE IN UNIX
$ touch file1 -> creates file 'file1'(if not exist) or changes time stamp(if already exist). This command will create zero bytes file with name file1
$ vi file1 -> 'vi file1' is VI Editor command for creating file. If you give vi file1, file1 will create and it will open for edit.


USAGE OF UNIX CAT COMMANDS
$ cat file1 -> display contents of 'file1'. It will just display the content of specified file(file1) in non edit mode.
$ cat < file1 -> display contents of 'file1'. It will also behave like above command
$ cat > file1 -> write contents to 'file1'. File will open with edit mode. It will get over write the previous file content
$ cat >> file1 -> append contents to 'file1'. File will open with edit mode. but here we can append over the specified file.
write command " $ cat >> file1" In command line. After editing press CTRL+D to come out.
$ cat file1 file2 -> display contents of 'file1' and file2' one after other


USAGE OF UNIX LS COMMANDS
$ ls -> lists all directories and files in current directory
$ ls d1-> lists all directories and files in target directory
$ ls -a -> lists all including hidden ones
$ ls -r -> lists all in reverse order
$ ls -R -> lists all recursively
$ ls -l -> lists with details ie long list $ ls -i -> lists with i node value
$ ls -F -> lists all with info on format(directory name with ‘/’ as suffix, executable files with ‘*’ as suffix etc.)
$ ls -l file1 -> lists details of file 'file1'


USAGE OF OTHER FILE HANDLING UNIX COMMANDS
$ file file1 file2 -> displays type of file 'file1' and 'file2'
$ more file1 -> page wise display of 'file1'
to view contents of 'file1' page wise(press space bar), line wise(press enter)
$ echo file1 -> It will also create file with zero bytes.


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

NOTE : All unix commands are case sensitive.