1

I want to change the value from 1521 to 1525 in FROM_HOST only in file gexhosts.cat:

FROM_HOST   db201521
TO_HOST     db201521

Is there a way to do that or some work around?

I would really prefer if we could use sed as I am using sed for many other activities of mine.

techraf
  • 5,941
  • Nope Sir. It definitely is similar, But not exactly what i was looking for. In fact, That was the very first page i looked into when i seeked google's help. Thanks again. – Abstract Circle Mar 30 '16 at 16:17
  • It's a duplicate because it's the same problem with the same solution. The fact that your particular strings (1521 and 1525) aren't mentioned is irrelevant, it's still a simple search and replace question. The linked-to duplicate provides answers for most of the basic search-and-replace queries. Read, understand, and extrapolate to your exact needs. This site prefers answers that teach rather than answers that spoon-feed. – cas Mar 30 '16 at 23:23
  • Understood. I agree with you on the spoon-fed part. – Abstract Circle Mar 31 '16 at 11:37

2 Answers2

1

You can do:

sed '/^FROM_HOST/ s/1521$/1525/' gexhosts.cat

To edit the file in place:

sed -i.bak '/^FROM_HOST/ s/1521$/1525/' gexhosts.cat

The original file will be backed up as gexhosts.cat.bak and the modified file will be gexhosts.cat.

If you don't want to keep a back up:

sed -i '/^FROM_HOST/ s/1521$/1525/' gexhosts.cat
heemayl
  • 56,300
0

You could do it like:

sed 's/\(FROM_HOST.*\)1521/\11525/' gexhosts.cat
Eric Renouf
  • 18,431