Quote:
Originally posted by Damian Ibbotson
I'm not entirely sure what you are trying to do but I think I get the jist of it.
The following example would do the sort of thing you are asking using awk. Just pass in the type (rocks or books), the existing count and the replacement count.
awk '$1==type && $2==count {sub(/.*/,newCount,$2)}{print}' type=rocks count=40 newCount=100 < yourFile
In sed, you would want to control the parameters using the shell. The example below assumes that the type and the count are separated by a single space and that there is no leading or trailing whitespace.
type=rocks; count=40; newCount=100
sed "/^$type $count$/s/$count/$newcount/" < yourFile
|
Hello damian,
Tnx for your quick replay.
However the most important thing is that the two lines appear one after the other
and only in that format exactly :
rocks 12
books 20
than, if that is the situation, I want to replace these 2 lines to:
rocks 100
books 200
If for example the line:
rocks 12
appears and not followed by the line:
books 20
than I don't want to change it at all.
I wanted to know whether sed can find a pattern of 2 lines:
rocks 12
books 20
and replace it by
rocks 100
books 200
Regards meirav