1

This question already has an answer here:

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.

marked as duplicate by Wildcard, Jeff Schaller, Anthon, don_crissti, Eric Renouf Mar 30 '16 at 16:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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. – Aravindhan K 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. – Aravindhan K Mar 31 '16 at 11:37
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, You're a miracle worker. You know that ?? Thanks much for the solution. Now i am on my way to respond to Eric 'cos his solution was right too. – Aravindhan K Mar 30 '16 at 16:14
  • @AravindhanK Glad i could help :) – heemayl Mar 30 '16 at 16:16
0

You could do it like:

sed 's/\(FROM_HOST.*\)1521/\11525/' gexhosts.cat
  • Hello Eric. It worked! I am shouting lotsa YAYs in my desk here. Thanks for making my life easier. – Aravindhan K Mar 30 '16 at 16:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.