Background: I have a bunch of filenames named username.sub in single letter directories under script_testing (first letter of username is the folder name). For every username.sub, I need to check if the line user.$username.contacts\t exists and, if not, append the line. I am having troubles with my code thus far. This should be a rather simple thing, I think. I am currently testing with 4 username.sub files in subdirectory "g." I have gone through many changes, this is how the script currently stands:
Path_to_files=$Path_to_files$( find $HOME/script_testing/ -type d -printf ":%p" )
sub_files=$Path_to_files$( find . -type f *.sub)
if grep user.$username.Contacts $username.sub; then
echo "Contacts already subscribed"
echo "subscribing to contacts"
echo -e "user.$username.Contacts\t" >> $username.sub
++ find /home/user/script_testing/ -type d -printf :%p
++ find . -type f g.sub '^*.sub'
find: paths must precede expression: g.sub
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
+ grep user.g.Contacts g.sub
+ echo 'Contacts already subscribed'
Contacts already subscribed
1. Why is it using the folder name ("g" in this instance) instead of the username?
2. Why is it not appending to the file? If I hardcode everything, it works correctly for one file. I think I am missing something simple.
3. If I were to get this working, how would I get it to do so for multiple subfolders? To clarify, there are 26 subfolders (one for each letter of the alphabet) containing multiple username.sub files (along with other files)