Operating System - HP-UX
1832656 Members
3270 Online
110043 Solutions
New Discussion

Fixing Record Length in a File

 
SOLVED
Go to solution
Michael Treacy
Advisor

Fixing Record Length in a File

I have a file with individual records with a length of 13187, which I need to truncate to 12701 with a script. AWK can't handle it -
Any ideas ?
6 REPLIES 6
KapilRaj
Honored Contributor

Re: Fixing Record Length in a File

Sorry we will need some more info ...

I am aware of awk can not handle more than "n" number of fields ?. I use cut if you are up to getting a number of fields

Kaps
Nothing is impossible
Scott Palmer_1
Trusted Contributor
Solution

Re: Fixing Record Length in a File

not sure if this will work or not, but it is off the top of my head

cat file | cut -c 1-12701 > newfile
Scott Palmer_1
Trusted Contributor

Re: Fixing Record Length in a File

not sure if this will work or not, but it is off the top of my head

cat file | cut -c 1-12701 > newfile

Regards

Scott
A. Clay Stephenson
Acclaimed Contributor

Re: Fixing Record Length in a File

Well, if you insist upon a script (and you are already familiar with awk) then use gawk, the Gnu version of awk. It does not have awk's 3000 char hard record lerngth and is a superset of standard awk.

http://hpux.connect.org.uk/hppd/hpux/Gnu/gawk-3.1.3/

Plan B (actually, this would be my Plan A): Use Perl.
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor

Re: Fixing Record Length in a File

What we need to know for whatever solution: are these records fixed width each on a seperate line or does the original file have no line endings at all?

in the latter case, cut won't work, and awk will not be very handy. you need either C or perl

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Michael Treacy
Advisor

Re: Fixing Record Length in a File

Thanks for all your help...
I needed a quick solution and cut seems to do the job...
I'll have to learn perl or download GAWK for a long term solution

THANKS !!!