Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleteing characters

Status
Not open for further replies.

abovebrd

IS-IT--Management
May 9, 2000
690
US
I have a data file with just over 1000 lines

I need to find a way to delete everything but the first 6 characters on each line. Using perl is not an option.

I was thinking of using SED, however I am drawing a blank on the general expression right now. If you have a suggestion I would love to here it.

-Danny
dcd@pop.mainstreet.net



-Danny






 
Well its not pretty but it worked.

I opened the file with vi,

then used the search and replace function

1,$ s/.......(60 dots)$//g

Each line had a consitant number of characters which I failed to metion.

However there must be a better (cleaner) method for doing this ?

-Danny






 
Danny,

Something like that would work in sed as well. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi,
I dont know what the maximum number of characters in each record is , but we will use 80 as an example.
for i in `cat yourfilename`
do
echo $i | cut -c7-80 >> newfile
done
 
Oops,
I read your question incorrectly, to keep the 1st six characters, the command should be:
echo $i | cut -c1-6 >> newfile
 
Or you could simply do

cut -c1-6 filename > newfile

Greg.
 

Hi

If you have 'awk' supported in your machine,
this will work...

#awk script file "script.awk"
#begin
cat $1 |
awk '{print substr($0,1,6)}'
#end

Save the above 5 lines in a file script.awk . Then run
it like this

script.awk <input file> > <output file>

You are done

-abp

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top