Quote:
Originally Posted by nextStep
The content of testresult.txt are as follows
Properties 20201020 281899 32000 Warning
Code:
...
sed -i "s/Warning/<font color="red">$3<\/font>/g;s/Normal/<font color="green">$3<\/font>/g" HotelDashboard.html
}
fn_presentationLogic
I have used the above sed command to substitute the third cell if it finds "Warning" but in vain. Could you please advise.
|
There are several problems.
Problem 1: sed doesn't have the notion of columns. For sed, $3 is just the string "$3", not the third column.
Problem 2: You don't quote correctly. The first double quote is matched with the double quote before
red. You then have an output redirection, $3, and input redirection plus more stuff. The result is probably an incorrect shell command, and definitely not a working
sed command. You could fix that by replacing the very first and very last double quotes with single quotes, but unfortunately, problem 1 will subsist.
Since sed doesn't know anything about columns, it is not the right tool for the task. awk, on the other hand, is well-suited. I would add the logic of colouring column 3 to the awk command that you have written already. First though, make sure that the current awk command generates the expected output.