Unix Text Manipulation Examples

In the following examples we will be using the following data file named data.
d e f 
1 2 3
x y z
a b c
7 8 9
4 5 6
To cat a file to the screen do the following:
% cat data
d e f 
1 2 3
x y z
a b c
7 8 9
4 5 6
To cut the second column of letters and numbers out the of the data file you could othe following:
% cat data | cut -c3
e
2
y
b
8
5
Another way to do the same thing using awk would be:
% cat data | awk '{print $2}' 
e
2
y
b
8
5
Notice that the cut command took the third character postion from the file and the awk commad took the second field from the file. NOTE: awk assumes the field separtor is a SPACE/TAB but you can use the -f option to change the field separator. To sort the file you could do the following:
% cat data | sort
1 2 3
4 5 6
7 8 9
a b c
d e f 
x y z
To file all lines in a file with an "y" in it you could do the following:
% grep y data 
x y z

Press here to return to the General Unix Software Menu.