[Clug-tech] Bash Scripting
sgrover at open2space.com
Tue Nov 21 02:32:28 PST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Never fails.. shortly after posting this message, I figured it out.
I used "grep -c mystring myfile" to get a count our how many matches are
found. So the code looks something like this:
position=`grep -c $targettext $MYFILE`
if [ $position -eq 0 ]
#... add text to the file ...
I suspect that this is just one way of many. Is there a better method?
> Hi all.
> I'm writing a bash script to automate some tasks. One of the tasks is
> to add a block of text to a file. The catch is that I only want this
> block of text added if it is not already there (otherwise there'd be
> multiple entries...)
> I know I can use grep to find the text in question, but I'm not sure how
> to use this in a bash script to equate to "this text exists".
> So, in pseudo code, I'm after this:
> targettext="some value"
> if ($targettext not in $MYFILE)
> echo $targettext >> $MYFILE
> How would I do this in bash?
> Thanks for any tips.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the clug-tech