I am running Ubuntu Linux. I am in need to print filenames & line numbers containing more than 7 columns. There are several hundred thousand files.
I am able to print the number of columns per file using awk. However the output I am after is something like
file1.csv-463
which is to suggest file1.csv has more than 7 records on line 463. I am using awk command awk -F"," '{print NF}' *
to print the number of fields across all files.
Please could I request help?
2
Answers
If you have GNU
awk
with you, try following code then. This will simply check condition ifNF
is greater than7
then it will print that particular file’s file name along with line number andnextfile
will take program to next Input_file which will save our time because we need not to read whole Input_file then.Above will print only very first match of condition to get/print all matched lines try following then:
This might work for you (GNU sed):
If there is no eighth column, break.
Output the file name
F
, the line number=
and print the current linep
.Feed the output into a paste command which prints three lines as one.
N.B. The
-s
option resets the line numbers for each file, without it, it will number each line for the entire input.