Say, the following is the content of a file$ cat fileName=TomValue=10Name=TomName=HarryValue=20On some occasion Value doesn't occur after a name. So what I need to do is find the Name=Tom pattern and replace value but only if occurs in the line immediately following the name. How to do that?
Using sed how to replace a pattern if it occurs on a line following another pattern?
awk;sed
More compact and somewhat easier:sed 'G;/^Value=/s/=.*\nName=Tom/=42/;s/\n.*//;h' fileThis appends the previous line from the hold space to each line. For Value= lines the value is replaced if Name=Tom was in the hold space. Otherwise the appended line is removed and the line is stored in the hold space for the next cycle.