< Awk
Content added Content deleted
imported>DrOwl No edit summary |
imported>DrOwl mNo edit summary |
||
Line 31: | Line 31: | ||
<pre> |
|||
[code] |
|||
listOfValues.txt |
listOfValues.txt |
||
Line 37: | Line 37: | ||
cup |
cup |
||
sox |
sox |
||
</pre> |
|||
[/code] |
|||
<pre> |
|||
[code] |
|||
data/2005.dat |
data/2005.dat |
||
size 0 t itsbig |
size 0 t itsbig |
||
thing 1 e teacup |
thing 1 e teacup |
||
magic 2 g holysox |
magic 2 g holysox |
||
</pre> |
|||
[/code] |
|||
<pre> |
|||
[code] |
|||
data/2006.dat |
data/2006.dat |
||
notsmall 0 t itsbig |
notsmall 0 t itsbig |
||
FnoRd 1 e teabag |
FnoRd 1 e teabag |
||
fNORd 2 g longsox |
fNORd 2 g longsox |
||
</pre> |
|||
[/code] |
|||
<pre> |
|||
[code] |
|||
listOfMatchedData.txt |
listOfMatchedData.txt |
||
big, size, notsmall |
big, size, notsmall |
||
cup, thing |
cup, thing |
||
sox, magic, longsox |
sox, magic, longsox |
||
</pre> |
|||
[/code] |
Revision as of 16:45, 26 May 2006
Search for $var in * files
This script get a value from listOfValues.txt and searches through all .dat files in the /data directory it pulls out the data in Colom 4 and apends it to one line of output we should really use Vars instead of filensmes and all that nice stuff but hay =)
searchData.ksh #!bin/ksh echo > listOfMatchedData.txt for x in `cat listOfValues.txt`; do awk ' $4 ~ /'$x'/ {found=found", "$1}; END { print "'$x'" found } ' data/*.dat >> listOfMatchedData.txt done
$4 means test colom 4
~ = partal match
/'$x'/ = /y/ says patern match, '$x' i used quotes becouse im using a varable from outside of awk.
{found=found", "$1} apends a , and data from colom 1 to the varible found
END = exacutes this code after the last file has been closed
{ print "'$x'" found } prints out $x (the value we were searching for) again i quoted this value as before and the found data
listOfValues.txt big cup sox
data/2005.dat size 0 t itsbig thing 1 e teacup magic 2 g holysox
data/2006.dat notsmall 0 t itsbig FnoRd 1 e teabag fNORd 2 g longsox
listOfMatchedData.txt big, size, notsmall cup, thing sox, magic, longsox