[Ilugc] searching within a text file

  • From: srinivasanr@xxxxxxxxx (Srinivasan R)
  • Date: Thu Jan 25 23:13:06 2007

On 1/25/07, Gopalarathnam Venkatesan <gopal@xxxxxxxxxxxxxxxxx> wrote:

baluk wrote:
i want to find out the first 30 characters in text file which has about
200 lines of text.i tried reading grep and sed but it seems to be little
above me..can any one help

Its quite easy using sed.

shell> sed 's/\(.\{30\}\).*/\1/
1q' FILE

or, if your system's sed supports the ``-e'' option, you can use:

shell> sed -e 's/\(.\{30\}\).*/\1/' -e 1q FILE


shell> head -c 30 filename

This would (also) work.

-- 
Next mail in %d minutes
cnu - http://cnu.livejournal.com
http://fslog.com - Free Software Blog

Other related posts: