Operating System - HP-UX
1831293 Members
2985 Online
110022 Solutions
New Discussion

search for data in a file column

 
SOLVED
Go to solution
John Carver
Frequent Advisor

search for data in a file column

I need to write into a script a search process that looks for data in a particular column of a file.
Attached is a small sample of what I am working with. Every now and then a damaged file shows up under the Damaged column heading.
I have not been successful in using sort or awk because there is data under the column heading only if there is a damaged file.
4 REPLIES 4
Rodney Hills
Honored Contributor
Solution

Re: search for data in a file column

With "awk" you can use substr to look at a specific column-
awk 'substr($0,30,1)="1"{print "bad line",$0}' yourfile

HTH

-- Rod Hills
There be dragons...
H.Merijn Brand (procura
Honored Contributor

Re: search for data in a file column

# perl -ane '@F==7&&$F[1]>0&&$F[2]>0&&print' your_data_file
INDEX.ADR.LINE.CITY 1 2 123 1 15503 1024
#

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Keith Clark
Valued Contributor

Re: search for data in a file column

At first I thought that you may be able to do something similar to what procura has done, but using the awk NF (number of fields) parameter. But I don't think you can consistently get the right answer, since Dynamic Modulo is sometimes empty as well. Is the original file tab delimited? That may help. If not, can you pad the columns with zeros?
John Carver
Frequent Advisor

Re: search for data in a file column

Once I added the second "=" character, the command returns any lines that have a single character length string of "1" in position 30.

awk 'substr($0,30,1)=="1"{print "bad line",$0}' myfile

Thanks for the help!