sed command
hi all
I am writing a unix script in which file name is test.txt . .txt shoud be replace as .flg this can be done using sed coomand but i want the o/p of sed to be stored in a variable #!bin/sh var="" sed -e 's/.txt/.flg' test.txt echo $var echo $var should print the result as test.flg how to do help me |
input="test.txt"
var=$(echo $input | sed "s/.txt/.flg/g") echo $var or what about : var=$(echo $input | sed "s/.txt$/.flg/g") (only replace .txt if at the end) |
i tried the above code
but it show an error'var=$' unexpected yes i want to replace .txt to .flg |
which shell are you using? Is it bash?
|
input="test.txt"
var=`echo $input | sed "s/.txt/.flg/g"` echo $var Using $(...) is just the new way of writing `...` |
I am using bash shell
I wrote the above coding #!bin/sh input="test.txt" var='echo $input | sed "s/.txt/.flg/"' echo $var It executes without errors but it does not print the value in var just shows a blank line |
All times are GMT -5. The time now is 06:55 AM. |