I have the below text in a file
I want to replace the above text with the below text using
Where version is a variable.
How can we do this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Since the path contains slashes, you probably don't want to use the common
/ character as the delimiter for sed. Here, instead of using
/ I use
$ echo $path_tryuio /this/is/some_path $ echo $path_tryuio | sed -e "s^/is^^" /this/some_path
Also note the use of double quotes instead of single quotes – the shell does not expand variables within single quotes.
Assuming you wanted the following modifed
and not what's on the right of
= as is normally to be expected, you can achieve this using
sed -e 's|path_tryuio=$path_opt/\(GMT/$CARGMT_VERSION\)|$path_track/GMT/cayu/station/\1|'
Note that in the above sed command what we have are single quotes, so the
$ variables will not interpolated, rather as literal strings.
$path_opt won't be treated as end of pattern space, since there is text after it.