Search This Blog

Sunday, 5 October 2014

Cut Command


TO GET VALUES BASED ON DELIMITER USING CUT COMMAND
cut -d ":" -f 1-1 Tfr3.txt > T10.txt

Delimiter is : (colon)
Position is 1 (one) through 1
This will get the data before first delimiter in File Tfr3.txt
Example:
Source:

Sales:123123:Aravind:1234
Sales:123124:Ram:1235
Sales:123125:Shankar:1236
Sales:123126:Ravi:1237
Sales:123127:Vinodh:1238
Sales:123128:Senthil:1239
Sales:123129:Saravana:1240

Output:
Sales
Sales
Sales
Sales
Sales
Sales
Sales

If the command is

cut -d ":" -f 2-2 Tfr3.txt > T10.txt
then we will get value in second delimiter

Output:
123123
123124
123125
123126
123127
123128
123129
If the command is

cut -d ":" -f 1-2 Tfr3.txt > T10.txt

Then we will get output including first and second delimiter ranging (1-2) and Output will be
Sales:123123
Sales:123124
Sales:123125
Sales:123126
Sales:123127
Sales:123128
Sales:123129
If the command is

cut -d ":" -f 1-3 Tfr3.txt > T10.txt
Sales:123123:Aravind
Sales:123124:Ram
Sales:123125:Shankar
Sales:123126:Ravi
Sales:123127:Vinodh
Sales:123128:Senthil
Sales:123129:Saravana
CUT command using other delimiters
cut -d "/" -f 2-2 Tfr3.txt > T10.txt

cut -d "(" -f 1-1 Tfr3.txt > T10.txt

cut -d ")" -f 3-3 Tfr3.txt > T10.txt

cut -d ";" -f 1-1 Tfr3.txt > T10.txt

cut -d "'" -f 1-1 Tfr3.txt > T10.txt
CUT command for Substring action
cut –c1-10 Tfr3.txt > T10.txt

This will cut the characters from position 1 to 10.


No comments:

Post a Comment