I am trying to write a shell script(or Perl Script) that would do the following:
I have a file that contains the following lines:
File:
https://ims-svnus.com/dev/DB/trunk/feeds/templates/shell_script.txt -r860
https://ims-svnus.com/dev/DB/trunk/feeds/perl/templates/perl_script.txt -r867
https://ims-svnus.com/dev/DB/trunk/cfg/temlpates/cfg_file.txt -r868
...so on
Script:
#!/bin/ksh
file=$1
path=/home/filter/
while read line
do
echo "Getting $line"
svn export $line /home/filter/feed/templates/<filename> --> need to Extract the file name from the url
done < $file
exit
Here:
I need to extract the file name from the above file that contains the lines:
using perl or shell script:
https://ims-svnus.com/dev/DB/trunk/feeds/templates/shell_script.txt -r860
https://ims-svnus.com/dev/DB/trunk/feeds/perl/templates/perl_script.txt -r867
https://ims-svnus.com/dev/DB/trunk/cfg/temlpates/cfg_file.txt -r868
...so on
Example:
if s/templates/
<then extract the file name as:>
shell_script.txt
so that the script would save along with the file name in that directory.
Could someone please help me out to extract the filename from the above url.
It would be greatly appreciated for your time and help.
I will have the following directories already created:
/home/filter/prod/bin
/home/filter/prod/cfg
I need to read line by line from the above file and do the following:
1) Somehow split the line based on the word "Templates" and then store the filename(ex: shell_script.txt) into a variable.($filename)
2) The other part of the splitted line should be stored in another variable.($path)
3) $path = reverse $path -- to extract the directory feeds, cfg ($1) (The directory should be created if it doesn't exists. i.e. /home/filter/prod/bin/feeds
4) then svn export <$line> <save to /home/filter/prod/$path/$filename)
i.e. the extracted file should save under that directory.