bash - sed removes part of the string when doing search/replace -


i have local files containing special characters square , regular brackets.

when trying replace part of filename sed filename being

the original file name looks this:

  • ddatum - ffirma - bbetreff (wwer) [tags_][beleg]_007246-1 copy.pdf

when doing sed replace results like:

  • 20161219 - ffirma - bbetreff (wwer) copy.pdf

another example:

  • original: ddatum - ffirma - bbetreff (wwer) [tags_][beleg]_007858.pdf
  • result: 20161231 - ffirma - bbetreff (wwer)

the sed command use is:

 newname=`sed -e 's/ddatum/'\$firstdate'/g' <<< "\$f"` 

$firstdate contains simple date string. $f contains original file name.

i suppose has literal characters. search has not rendered useful far. support.

this it:

newname=`sed -e "s/ddatum/$firstdate/g" <<< "$f"` 

example:

$ f="ddatum - ffirma - bbetreff (wwer) [tags_][beleg]_007246-1 copy.pdf" $ firstdate="20161231" $ newname=`sed -e "s/ddatum/$firstdate/g" <<< "$f"` $ echo $newname  20161231 - ffirma - bbetreff (wwer) [tags_][beleg]_007246-1 copy.pdf 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -