Command required in shell script.

Hi All

I have thousands of files. Each files are having lines with different length. I need to print those filenames whose length of the lines are more than 15.
Contents of the files can have space as well as any special characters.

eg

File1 have below content:

Cat File1

123456789
1234567
123456789|121|fasdf

File2 have below content:

Cat File2

12345612|12|342
2351ada|123|qw

Output of the command should be File1 as it has one line in it "123456789|121|fasdf" having length more than 15.

Thanks in advance

See if this awk fills your requirment :

awk '{a=length($1); if (a > 15) print FILENAME}' *.txt

Where *.txt is all the files you want to process.

Hi Its working fine but can you please explain how it works. Thanks

We will declare a variable a as a length of first field ($1).
Then if a is greater then 15, we shall use awk builtin variable FILENAME and print it in output.

FILENAME is the currently processed file.

How its reading every line to check the length of each line....?

I thought we can use only while read line

Read about AWK and how it processes files.

Bunch of tutorials can be found online with alot of examples.

Contents of the files can have space as well as any special characters

if the file have space, then the given awk command will not work.

example :

 
abcdefg
abcd efgh ijklmnopqrstuv
abcdefg

---------- Post updated at 02:17 PM ---------- Previous update was at 02:15 PM ----------

Try this..

 
for i in *.txt; do nawk 'length($0)>15{print FILENAME;exit}' $i; done

Special chars will work fine as long as FS is space.

Lines with whitespace won't work.

Regards
Peasant.