[olug] Unix Tip: OPERATING ON MULTIPLE FILES
Unix Guru Universe
listserv at ugu.com
Wed Feb 19 19:24:50 UTC 2003
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE
UNIX HOT TIP
Unix Tip 1876 - February 19, 2003
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
OPERATING ON MULTIPLE FILES
Have you ever felt the need to perform a
set of operations on multiple files
simultaneously???
Here is a solution for that.
For instance, if it is required to perform
multiple operations like searching a string
(using grep), and executing an awk or perl
script etc, etc. on not just one file but a
set of files, use the following commands at
the unix prompt:
$<: foreach i (<file_list>)
? echo $i
? grep <search_pattern> $i > tmp
? awk -f awk_script tmp >> report
? ....
? ....
? end
$<:
The files list in the brackets can be either
* Specifically mentioned
* A unix variable which contains a list of
file names. For instance, the variable
"p" can be assigned all the files starting
with string "data" as follows:
set p = (data*)
Other examples are:
set g = `grep -l "Startpoint" * `
or
set all = *
(This assigns all file names in the current
directory to the variable "all" )
And its usage with the "foreach" command will
be as follows:
$<: foreach i ($all)
.....
.....
end
This tip generously supported by: lakshmi at virtualipgroup.com
--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today
==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.
Unix Guru Universe - www.ugu.com - tips at ugu.com - Copyright 1994-2001
==========================================================================
More information about the OLUG
mailing list