Operating System - HP-UX
1752477 Members
5713 Online
108788 Solutions
New Discussion юеВ

Re: How manage very long line

 
SOLVED
Go to solution
SILVERSTAR
Frequent Advisor

How manage very long line

Hi,

I have a file, each line inside has a variable lenght and is terminated by a carriage return.
Line lenght may be long 4000 char.

In each line I have to substitude the the word 'blabla' with word 'ccccc'.

I am not able to manage so long line with awk or vi, each time i get the error 'line lenght too long'.
Foe example when I use awk the error is:
awk: Input line 0 cannot be longer than 3,000 bytes.

Thank for any suggestion.

Angelo
8 REPLIES 8
Sandeep_Chaudhary
Trusted Contributor

Re: How manage very long line

This is from one of the forum:

get a copy of GNU awk and put its directory as the first into tha $PATH of your scripts.
GNU awk does not have that limit, IIRC...
SILVERSTAR
Frequent Advisor

Re: How manage very long line

Hi,

as per other forum I checked gnu awk at this site http://hpux.cs.utah.edu/ but it has been removed.

Do you know any other site ?

thanks
Angelo
Sandeep_Chaudhary
Trusted Contributor

Re: How manage very long line

Re: How manage very long line

Angelo,

I don't think sed has this limitation...

Try:

sed -e 's/blabla/ccccc/g' myfilename

HTH

Duncan

I am an HPE Employee
Accept or Kudo
James R. Ferguson
Acclaimed Contributor

Re: How manage very long line

Hi Angelo:

Perl doesn't have limitations like this.

# perl -pe 's/blabla/ccccc/g' myfilename

Regards!

...JRF...
SILVERSTAR
Frequent Advisor

Re: How manage very long line

Hi,

using both sed and perl each command goes in stuck with no error.
The ony thing i can do at that point is to kill the process, but the file is not changed.

rgd
angelo
James R. Ferguson
Acclaimed Contributor
Solution

Re: How manage very long line

Hi (again) Angelo:

> using both sed and perl each command goes in stuck with no error

You also said that a carriage-return delimits each line.

If you truly have only carriage-returns (\015) without newlines (\012), then seeing any output on your terminal won't occur. This may be very misleading. Do:

# perl -pe 's/blabla/ccccc/g' myfilename > myfilename.new

...or, update in-place while preserving a backup copy of the original file as "*.old" :

# perl -pi.old -e 's/blabla/ccccc/g' myfilename

Regards!

...JRF...
SILVERSTAR
Frequent Advisor

Re: How manage very long line

Using perl i get the right file !
thanks to everybody, overall JRF.

Angelo