[HPADM] Re: Using sed or awk

From: MuthuKumar (kmuthukumar@lycos.co.uk)
Date: Wed Oct 06 2004 - 23:30:59 EDT


> have a file that has records in it that are 133 characters in length. The
> actual data needed is only 54 characters the rest of the record is spaces.
> What I need to do is get the first 54 characters from each record. I need
> all 54 characters whether the are space or not. Any suggestions would be
> appreciated.

We can do this as,

    sed:

        sed "s/^\(.\{46\}\).*/\1/" filename

    It will get the first 46 characters of every record on filename

    awk:

       awk '{ print substr($0,1,46) }' filename

    cut:

        while read line; do

            echo $line | cut -c1,46

        done < inputfile

    Try any of the above.

HTH.

REgards
Muthukumar.

---
===============  It is a "Virus Free Mail" ===============
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.773 / Virus Database: 520 - Release Date: 10/5/2004 
--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:43 EDT