Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

How to Awk examine file.txt in tree folder?

73 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

ne...@tin.it.no

lukematon,
7.2.2016 klo 5.18.207.2.2016
vastaanottaja

Hi all

A simple matter

How to awk examines files in a folder tree, recursively?


Thanks in advance

Regards





--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Kenny McCormack

lukematon,
7.2.2016 klo 5.38.367.2.2016
vastaanottaja
In article <n975l9$mcs$1...@adenine.netfront.net>,
ne...@tin.it <ne...@tin.it.NO> wrote:
>
>in advance How news://freenews.netfront.net/ tree, all Regards examines -
>Thanks simple a complaints: to ne...@netfront.net files --- in recursively?
>matter --- folder Hi awk A

--
The motto of the GOP "base": You can't *be* a billionaire, but at least you
can vote like one.

Janis Papanagnou

lukematon,
7.2.2016 klo 5.42.217.2.2016
vastaanottaja
On 07.02.2016 11:17, ne...@tin.it wrote:
> Hi all
>
> A simple matter
>
> How to awk examines files in a folder tree, recursively?

Simplified answer; with awk you can't. More accurately; it's tedious
to implement. So best use your shell capabilities to do the recursion
(in Unix e.g. the find command) and apply the file list to your awk.
(Details are OS dependent, and OT in this group.)

Janis

Ed Morton

lukematon,
7.2.2016 klo 11.18.317.2.2016
vastaanottaja
On 2/7/2016 4:17 AM, ne...@tin.it wrote:
> Hi all
>
> A simple matter
>
> How to awk examines files in a folder tree, recursively?
>
>
> Thanks in advance
>
> Regards

A big hurdle to newcomers to UNIX is accepting that the UNIX approach is to
combine multiple small, specialized tools to solve problems, not to have
jack-of-all-trade tools that do everything, and after that to learn which tools
are the right ones for which job.

In this case, the general purpose UNIX tool to manipulate text file contents is
"awk" and the UNIX to find files is "find" and the UNIX tool to call another
tool based on it's input is "xargs" so one solution would be:

find <args> | xargs awk '<script>'

Check the man pages and google examples of find, xargs, and awk.

Ed.

Marc de Bourget

lukematon,
7.2.2016 klo 15.41.287.2.2016
vastaanottaja
With TAWK for Windows, you can do this.
I don't know how to implement this with GAWK, though.
For TAWK users, here is the code for TAWK:

# scandir.awk

# Make a path by adding a filename onto an existing path.
# If the path is just "/" or something like "C:", then we do not
# need to include another "/" in the path.
function makepath(pathname, fn) {
if (pathname ~ /[:/\\]$/)
return pathname fn
else
return pathname "\\" fn
}

function scanlist(directory, extension) {
local fn
local mode
local FILELIST
local ext = "\\." tolower(extension) "$"

if (getdirlist(directory, FILELIST)) {
# Print out the regular files:
for (i in FILELIST) {
fn = makepath(directory, FILELIST[i])
mode = filemode(fn)
if (substr(mode,1,1) == "f") {
if (tolower(fn) ~ ext) {
# Print file names:
print fn
while ((getline inline < fn) > 0) {
# Print file content or do other things:
# print inline
}
close(fn)
}
}
}

# Now recursively list sub-directories
for (i in FILELIST) {
# Skip over directories that begin with "." (like "." and "..")
if (substr(FILELIST[i],1,1) == ".")
continue
fn = makepath(directory, FILELIST[i])
if (substr(filemode(fn),1,1) == "d") {
scanlist(fn, extension )
}
}
}
else {
print "Can not find directory:", directory
}
}

BEGIN {
# First argument: Directory to scan recursively.
# Second argument: Extension of files to examine.
# For all files, use "*"
scanlist("c:\\testdirectory", "txt")
}

Joe User

lukematon,
7.2.2016 klo 16.52.277.2.2016
vastaanottaja
Marc de Bourget wrote:

> With TAWK for Windows, you can do this.
> I don't know how to implement this with GAWK, though.
> For TAWK users, here is the code for TAWK:
>
> # scandir.awk
>
> # Make a path by adding a filename onto an existing path.
> # If the path is just "/" or something like "C:", then we do not
> # need to include another "/" in the path.
> function makepath(pathname, fn) {
> if (pathname ~ /[:/\\]$/)
> return pathname fn
> else
> return pathname "\\" fn
> }
>
> function scanlist(directory, extension) {
>

Maybe something like this untested code:

function fnams(dir, ext, arrayout, cmd, s)
split("", arrayout)
cmd = "find \"" dir "\" -iname \"*." ext "\" "
while (cmd | getline s) {
arrayout[length(arrayout)+1) = s
}
}



Aharon Robbins

lukematon,
7.2.2016 klo 23.38.347.2.2016
vastaanottaja
In article <7fd2643a-145b-4440...@googlegroups.com>,
Marc de Bourget <marcde...@gmail.com> wrote:
>With TAWK for Windows, you can do this.
>I don't know how to implement this with GAWK, though.

The fts function in the filefuncs extension would probably be of use
here. Code left as an extercise for the reader.

>For TAWK users,

All 6 of them.
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com
Viesti on poistettu
0 uutta viestiä