I tried the following command in my script:
find=grep "$jasper" jasperreports.properties | awk -F"reports/" '{print $2}'
Example output:
maps
I want to change this output to something else, e.g. charts
. For that, I tried:
sed -i /"$find"/charts
sed
is causing me problems, it needs an input file but I don't have one. Is there a way to pipe the output from grep and awk to sed?
You can always provide a pseudo-file with the
< <(command)
process substitution syntax:-i
can only be used with sed if you're passing a file, it means "inline replace". Without this, the output of sed would be written tostdout
(usually the console output). With-i
, it does an inline replacement, that is, doing replacements in the file itself.The next code reads the contents of
jasperreports.properties
into the variable$input
(line 1) and finds the string to be replaced (line 2).On the third line, it outputs the input string and pipes it through
sed
for replacement.sed
outputs the string tostdout
which will be caught by$(
and)
, and therefore be stored in$input
.If you want to apply the changes immediately to the file:
From
man sed
:other solution ()
find=$(grep "maps.base" jasperreport.properties | awk -F"reports/" '{print $2}';sed "s/$find/$host/" jasperreport.properties > tmp.txt.txt && mv tmp.txt jasperreport.properties
what am trying to do is the following :
1.find all files in directory that have name jasperreport.properties(which include 3 lines as you see from previous code ,three lines same only different word"maps,charts,widgets" )
2.point to each line individually and change host ip address for 3 three lines , with take concern of keeping "maps,charts,widgets" in the middle and "Maps,Charts,Widgets" at the end and as you see the 3 words at the end start with capital ...