I need to achieve the following using a bash script.
I have a text file I need to read. The Portion of the text file I am interested reads something like this : This fund is pledging up to $300 towards the cost of health care for John Smith.
I need to read the name of the patient into a variable $name = John Smith. The two words after ,towards the cost of health care for should be stored in my $name variable for later use.
I have tons of such files in /patients/txt/ directory.. so this is what i want to achieve
for $i in $LIST
...open txt file
...read the name into $name [ explained above ]
...there is another directory with pdfs, and every txt file being read, has a corresponding pdf file with the same name (besides extension) in the pdf directory. [ Eg: /patients/pdf/pg_0001.pdf AND /patients/txt/pg_0001.txt ]
...i want to rename pg_0001.pdf with $name, with a underscore between first and last name: john_smith.pdf
SO in the end I will have read all my text files in the txt folder, and renamed all my pdf's based on the name i read.
TEXT FILE $name READ FILE RENAMED
pg_0001.txt John Smith pg_0001.pdf to John_Smith.pdf
pg_0002.txt Jane Doe pg_0002.pdf to Jane_Doe.pdf
pg_0003.txt Mary Johnson pg_0003.pdf to Mary_Johnson.pdf
and so on...
My directory structure is as follows:
pg_0001.txt , pg_0002.txt, pg_0003.txt .........
pg_0001.pdf, pg_0002.pdf, pg_0003.pdf .........