cancel
Showing results for 
Search instead for 
Did you mean: 

grep

SOLVED
Go to solution
PK_1975
Frequent Advisor

grep

Hello

Could you tell me the command for the following requirement,

I want to delete a line by finding a word AB at positions 431 and 432 in a file, and copy into a new file with the remaining lines.

Thank you
11 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: grep

Hi:

One way:

# perl -ne 'print unless /.{430}AB/' file > file.new

Note that Perl counts characters starting from zero. That is, the first character of every line is character-0.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: grep

Hi (again):

...and since you specifically mentioned 'grep' :

# grep -vE .{430}AB file > file.new

Regards!

...JRF...
PK_1975
Frequent Advisor

Re: grep

Hello

The command you provide perl and grep is not working

below is the error I got with grep

grep -vE .{430}PA file > file.new
grep: Invalid {} repetition.


the line starts with "1" and at positions 431 and 432 we have P & A, I want to delete those line of that type in the file
James R. Ferguson
Acclaimed Contributor

Re: grep

Hi:

OK, so the 'grep' gives:

grep: Invalid {} repetition.

This means that this version of 'grep' doesn't handle "large" repetions. That's why I suggested Perl in the first place, since it lacks silly limits. Adjust your counting to be from zero instead of one and use Perl.

Regards!

...JRF...
PK_1975
Frequent Advisor

Re: grep

Hello

I am sending a test file, please tell me how to delete a line

In the file first letter as "1" in red and "PA" in red, PA Starts at position 431, I want to delete those type of line in every file.
OldSchool
Honored Contributor

Re: grep

that looks suspiciously like real account information.....

which shouldn't ever be posted....


Dennis Handly
Acclaimed Contributor

Re: grep

>JRF: grep: Invalid {} repetition.
>This means that this version of grep doesn't handle "large" repetitions.

You can simply add up repetitions:
grep -v '^.\{200\}.\{230\}AB' file > file.new

>In the file first letter as "1" and "PA", PA Starts at position 431

If that "1" is important you can use:
grep -v '^1.\{200\}.\{229\}AB' file > file.new
James R. Ferguson
Acclaimed Contributor

Re: grep

Hi (again):

> Dennis: You can simply add up repetitions:

Yes, of course you can, but this is a nuisance. If the OP is fixed on 'grep', though, I agree that factoring is all that's left :-)

Then again, the above [ grep -vE .{430}PA file ] worked with GNU's 'grep' :-}}

Regards!

...JRF...
PK_1975
Frequent Advisor

Re: grep

Hello

I tried with ur suggestions, but it failing and getting this error

grep: Invalid {} repetition
James R. Ferguson
Acclaimed Contributor

Re: grep

Hi (again):

> I tried with ur suggestions, but it failing and getting this error:
grep: Invalid {} repetition

Well, I don't think you tried the factoring Dennis suggested! Empirical analysis suggests that the maximum repetition is 255. As I said, above, this is one choice; another is Perl; and yet another is GNU's 'grep'.

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: grep

>JRF: Empirical analysis suggests that the maximum repetition is 255.

255 is right there on the man page, regexp(5):
http://docs.hp.com/en/B2355-60130/regexp.5.html