Pattern replacing in a file
Hi
I want to replace a pattern in a file.The file format is given below. . . 111111 path=/home/fun/ 222222 path=/home/fun/ 333333 path=/home/fun . . . . . I want to replace "path=/home/fun" with another pattern, but only under "111111", all the others should be the same. Thank you in advance for your valuable help.... |
Hi,
Did you find a solution or did something else go wrong while posting? If you did find a solution, please post it for future reference (others might have the same problem). |
Hi
Do you have a question to ask? A title and a hat tip don't qualify as a question... |
Sorry for the trouble...it was a mistake while posting...now the question is edited..
|
What have you tried so far? It should be a simple task for sed if you are a bit experienced with it. For example (not tested) by reading the next line when it encounters the pattern 111111 and doing the substitution accordingly:
Code:
sed '/^111111$/{n;s%path=/home/fun%something%}' file |
Quote:
Thanks for your suggestion, but it is not working... I know that it can be done using sed, but dont know how to!!! |
Hi,
What's the (error) message you get when executing colucix command (which looks correct). |
Quote:
There is no error messages seen. But no editing is done in the file, it remains the same. |
|
Hi,
Add the -i.bak switch to the command (and do take a look at the link pixellany provided). sed -i.bak '/^111111$/{n;s%path=/home/fun%something%}' file A backup of the original file is made (with .bak as extension). |
Quote:
|
Or just redirect to a new file...
eg: sed 'stuff' oldfile > newfile |
Looks like homework
|
@Gridley: That's very nice, especially after this is already solved.
BTW: Why do you think this, or are you just increasing your post count. |
Ummmmm.........because it looks like homework ??
|
All times are GMT -5. The time now is 03:15 PM. |