To get any n characters of each line from a file, use cut.
Code to get first 3 characters of file
cut -c1-3 filename
217
207
284
238
216
219
Other examples
1) Get just specific character
echo "your text here" | cut -c2
> o
2) Get everything from a character
echo "your text here" | cut -c2-
> our text here
3) argument -f can be used to get specific fields from the file. Default delimiter is tab. It can be overridden by -d.
e.g.
cat rhyme
>
jack , and jill, went
up the,hill
to fetch,a pail
of water.
cut -f1 -d, rhyme
>
jack
up the
to fetch
of water.
4) argument -s along with -f is used to suppress lines that do not contain the field delimiter.
cut -f1 -d, -s rhyme
>
jack
up the
to fetch
5) Get a range of fields
cut -f2-3 -d, -s rhyme
>
and jill, went
hill
a pail
Cut option -b can be used to obtain same results as -c.
Wednesday, December 2, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment