Operating System - HP-UX
1753784 Members
7104 Online
108799 Solutions
New Discussion юеВ

Re: Need a perl script to find whether all of the column values present

 
kumar143
Occasional Contributor

Need a perl script to find whether all of the column values present

eg:
columns;
a,b,c,d,e,f,g

there are million records, i need to check whether each row is containing 7 columns. if any of the row containing less than or more than 7 then those records should redirect to file.
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Need a perl script to find whether all of the column values present

Hi:

Perl or 'awk' will easily do this. You don't way what your column delimiter is, so we will assume whitespace:

# perl -nae 'print if @F != 7' file > file.out

# awk 'NF<7||NF>7' file

Regards!

...JRF...
Stephen Keane
Honored Contributor

Re: Need a perl script to find whether all of the column values present

I'd guessed comma separated, as in his example.
Dennis Handly
Acclaimed Contributor

Re: Need a perl script to find whether all of the column values present

>JRF: # awk 'NF<7||NF>7' file

Wouldn't this just be: :-)
awk 'NF != 7' file
James R. Ferguson
Acclaimed Contributor

Re: Need a perl script to find whether all of the column values present

Hi (again):

> Dennis: > JRF Wouldn't this just be: :-)
awk 'NF != 7' file

Yup, of course! I guess I wanted to make the 'awk' look a bit longer. I too realized the silliness after I posted that :-}}

Regards!

...JRF...