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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using awk recursivly 1

Status
Not open for further replies.

JohanS123

Technical User
Apr 27, 2009
2
FR
Dear awk experts

I am rather new to awk (I am using awk on a WinXP machine via GnuWin32) and I am trying to do the following:

1. Loop through all subdirectories
2. If there is a file called file.txt then perform some awk commands (that I have and that are working)

In Linux this would be rather easy, using windows batch files perhaps as well, but the programming language of .bat files remains a mystery to me. So I was hoping that I can use only awk for this - but I have no idea of how... Is it even possible?

Thanks,
Johan S
 
Hi

Sorry for not answering to your question. Anyway, [tt]awk[/tt] does not have file system functions, so you can not solve it only with [tt]awk[/tt].

I suggest to use CygWin. That gives you a whole POSIX environment, so most of your old [tt]bash[/tt] scripts will run flawless. Then you can do it in the usual way :
Code:
find /dir/ -type f -name file.txt -exec myfair.awk '{}' \;

[gray]#or[/gray]

find /dir/ -type f -name file.txt | xargs myfair.awk
( I not know GnuWin32. If it also provides full POSIX environment, just skip my comment. )

Feherke.
 
Thanks!

Meanwile I did some digging into batch files, it sure is an ugly language, but this seems to do the trick. I post it here if anyone else is looking...
---
@ECHO OFF
echo Running awk on all PT1.trk files
for /f "delims=" %%i in ('dir /ad/s/b') do (
cd %%i
if exist PT1.trk (
echo Found PT1.trk in folder %%i
awk "{if (NF>1){print $0}}" PT1.trk > temp.txt
awk "ORS=NR%%3?\" \":\"\n\"" temp.txt > Sort_trk.txt
del temp.txt
del PT1.trk
)
cd ..
)
---
Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top