Home > Archive > AWK > January 2005 > apply rule to several expressions?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
apply rule to several expressions?
|
|
| Gernot Frisch 2005-01-28, 8:55 am |
| Assume this dir:
a.txt
b.txt
c.dat
d.inf
ls -1 | awk ???
so that .dat and .inf files will be processed.
-Gernot
| |
| Ulrich M. Schwarz 2005-01-28, 3:56 pm |
| "Gernot Frisch" <Me@Privacy.net> writes:
> Assume this dir:
>
> a.txt
> b.txt
> c.dat
> d.inf
>
> ls -1 | awk ???
> so that .dat and .inf files will be processed.
Try
awk -f thescript `ls -1 *.{dat,inf}`
but beware of irregular filenames like "-v FS=: .dat"
Ulrich
--
"A real Klingon warrior does not care about pineapple-oriented
languages."
-- galibert in the sdm
| |
| Ed Morton 2005-01-28, 3:56 pm |
|
Gernot Frisch wrote:
> Assume this dir:
>
> a.txt
> b.txt
> c.dat
> d.inf
>
> ls -1 | awk ???
> so that .dat and .inf files will be processed.
Assuming you want to process the output from ls rather than process the
files themselves:
ls -l | awk '/\.(int|dat)$/'
Ed.
| |
| Ted Davis 2005-01-28, 3:56 pm |
| On Fri, 28 Jan 2005 12:02:19 +0100, "Gernot Frisch" <Me@Privacy.net>
wrote:
>Assume this dir:
>
>a.txt
>b.txt
>c.dat
>d.inf
>
>ls -1 | awk ???
>so that .dat and .inf files will be processed.
If you want to process the files themselves, then
awk -f foo *.dat *.inf
where foo is the script. If it is necessary to process each file
separately, then use something like
{
if( OldFname != FILENAME ) {
OldFname = FILENAME
OutFile = something based on FILENAME
}
file processing code here, writing to OutFile
}
--
T.E.D. (tdavis@gearbox.maem.umr.edu)
| |
| Bob Harris 2005-01-29, 3:55 am |
| In article <35ukacF4s5dfvU1@individual.net>,
"Gernot Frisch" <Me@Privacy.net> wrote:
> Assume this dir:
>
> a.txt
> b.txt
> c.dat
> d.inf
>
> ls -1 | awk ???
> so that .dat and .inf files will be processed.
>
> -Gernot
ls -l *.dat *.inf
ls -l *.dat *.inf | awk '{print $9, $5}'
ls -l | awk '/\.inf$/ || /\.dat$/ { print $9, $5}'
This last example actually brakes if any of the entries are symbolic
links, so
ls -l | awk '
/\.inf$/ || /\.inf ->/ { print $9, $5}
/\.dat$/ || /\.dat ->/ { print $9, $5}
'
and the print $9 part breaks if there are spaces or tabs in the file
name. But I'll leave that as an exercise for the reader :-)
A lot depends on exactly what you want to do.
Bob Harris
|
|
|
|
|