Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search files containing blanks at beginning

Status
Not open for further replies.

karacharlie

Programmer
Dec 19, 2004
14
DE
Hi
I have several files e.g. file1 file2 file3
I'd like to find out which of these files contain six blanks at
the beginning of at least one line within the file:
e.g.
file1:
<blank><blank><blank><blank><blank><blank>12345 4343
<blank><blank><blank><blank><blank><blank>87584 394
647364 34783

file2:
34637
sdfer2348r52
488

file3:
74 745674
<blank><blank><blank><blank><blank><blank>34
343289453

So the script should give as result:
file1 and file3
 
Code:
/^      / { files[++i] = FILENAME }
END {
 for (i=1; i in files; i++)
   print files[i]
}
 
thanks for your post
now I have the list, but now I get the name of the file as many as I have the blanks within the file. I'd like to have a distinct list like:
file1
file2
and not
file1
file1
...
file2
file2
...
file2
 
Code:
/^      / { print FILENAME; nextfile }

Let me know whether or not this helps.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features.Under Solaris, use /usr/xpg4/bin/awk.

For an introduction to Awk, see faq271-5564.

 
Hi,
yes it works on my desktop system, but on a NCR Teradata (old version) it does not work. Maybe I try to embed an awk command like << awk ' /^ / {print "rm -f " FILENAME ; exit 0; }' >> into a shell script
for (i in 'ls filenames') do awk ... done, do you have any ideas?
 
If those files reside below the same dir and have something in common in the name you can do also:
egrep -l "^ " file_spec*
 
/^ /{++files[FILENAME]}
END{for(i in files)print i}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top