Operating System - HP-UX
1833062 Members
2727 Online
110049 Solutions
New Discussion

Equivalen of perl one liner for choping columns in large feed file

 
SOLVED
Go to solution
Srikanth Arunachalam
Trusted Contributor

Equivalen of perl one liner for choping columns in large feed file

Hi All,

I have a perl one liner to determine values in specific column position to determine. To be specific, I am checking for column position 12 to 14 to be in specific value using following perl one-liner.
CNT_INV=`/usr/bin/perl -ne 'print if substr($_, 12, 2) != "87"&&substr($_, 12, 2) != "77"&&substr($_, 12, 2) != "30";' CPR_01_01_2006_G1556V01.PROCESSED|wc –l`

I would like to know equivalent shell one-linner using awk to check across feed file for column position 12 to 14 for a specific value.

Any suggestion will be much apprecialted.

Thanks,
Srikanth A
4 REPLIES 4
Srikanth Arunachalam
Trusted Contributor

Re: Equivalen of perl one liner for choping columns in large feed file

Hi All,

Sample feed contents is
0101011273043001015466506001/01/2006
0101046163027701015466506001/01/2006

The one-liner checks for specific customer number not starting with 87, 77 or 30.

Thanks,
Srikanth A
James R. Ferguson
Acclaimed Contributor
Solution

Re: Equivalen of perl one liner for choping columns in large feed file

Hi Srikanth:

Perl's '$_' is awk's '$0' in this case. Perl counts zero-relative while awk counts one-relative.

Hence:

# echo "abcdefghijkl87op"|perl -ne 'print if substr($_,12,2) != "87"'

...becomes:

# echo "abcdefghijkl87op"|awk '{if (substr($0,13,2) != 87) {print}}

Regards!

...JRF...




Srikanth Arunachalam
Trusted Contributor

Re: Equivalen of perl one liner for choping columns in large feed file

Many thanks James. As usual you are rocking !


Srikanth Arunachalam
Trusted Contributor

Re: Equivalen of perl one liner for choping columns in large feed file

Choping concept is clearly specified.