hi all,
rather new scripting , starting learn has become necessary. enjoying it, having trouble following...
within file, have line contains "example0004.txt" want have identified , replaced other numeric code (0006 or something). having trouble locating "example0004.txt" replace (the new filename has been established). have:
sed -e "s/example*.txt/$filename/g" foo.txt > bar.txt
doesn't pick when script runs.
have suggestions or advice?
cheers
in regexes used sed * not consume chars in bash, adds 'any number' modifier symbol preceding it. thing - dot means 'any char', in case exampl[any number of 'e'][any symbol]txt
ignore me using echo feed example data sed. sed expression work same in case. dots troublesome, put them in [ ] enumeration of allowed chars (which [ ] used for) strips special meaning of dot. [0-9]* means sequence of digits, \1 , \3 return values of capturing groups (parentheses, counting 1)code:$ x=666; echo 'example111.txt' | sed -r 's/(example)([0-9]*)([.]txt)/\1'$x'\3/g' example666.txt
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Regular expressions help (sed)
Ubuntu
Comments
Post a Comment