views:

34

answers:

2

How do I append a string to all the files in a directory that starts with a particular string?

I tried,

cat mysig >> F*

But instead of appending contents of mysig to all files starting with F, it creates a file named "F*". Obviously wildcard doesn't seem to work. Any alternatives? Thanks in advance.

Edit: Also how do I delete this newly created file "F*" safely?. Using

rm F*

would delete all the files starting with F which I wouldn't want.

+4  A: 

The shell can't do that directly, since there will only be a single stream coming from the source program (the cat, in this case).

You need a helper program, such as tee. Try this:

$ cat mysig | tee -a F*
unwind
Thanks that worked!.
learner135
+2  A: 
for f in F*
do
  echo "string" >> $f
done

* is a special character - you need to quote it

rm 'F*'
Anton