bash - Editing a variable inside of a script with sed -
perhaps i'm stetching bash bit far, have variable containing list of urls.
#!/bin/bash /* returns /path/page/one.php /path/subseciton/ /path/to/this/section/ /path/to/yet/aother_section/about.php etc */ list_of_urls = $(pull_urls.sh) then have loop running, pulling text content old server , new server. on each of i'm running various diff commands see has changed.
for in $urls echo $i storage_area=./working/$i/ mkdir -p $storage_area xidel http://oldserver/$i -e '//div[@id="maincontent"]//p' > $storage_area/old.txt xidel http://newserver/$i -e '//div[@id="content"]//p' > $storage_area/new.txt diff $storage_area/old.txt $storage_area/new.txt > $storage_area/diff.diff wdiff $storage_area/old.txt $storage_area/new.txt > $storage_area/wdiff.wdiff done my problem need remove trailing slash. advisable in following way?
// inside loop, before xidel calls i=$(echo $i | sed -e 's/\/$//g')
how in way:
kent$ i=foo/ kent$ i=${i%/} kent$ echo $i foo if prefer doing sed, consider use separator other /, since want use slash in pattern:
kent$ i=/path/to/this/section/ kent$ i=$(sed 's#/$##'<<<"$i") kent$ echo $i /path/to/this/section
Comments
Post a Comment