Following are the points for your posts.
1st: Kindly use code tags as per forum rules while using codes/commands/inputs in your posts. You can go through the link for forum rules as follows. https://www.unix.com/misc.php?do=cfrules
2nd: There is no need of using cat file | sed .... here. As sed can read file by itself.
3rd: Following is an example for uses for sed command.
Let's say we have an example input file named test2 where we want to substitute a string named Control with chumma, then we can use as follows.
Output will be as follows.
4th: For more information on sed you can read manual page entry for it by man sed or you can go through n number of example by search utility option in this forum itself.
@Ravinder: Yes, it is perfectly OK to remind people to read the man pages. This point can never be stressed enough. On the other hand, "read the man page" or "search the web" without even so much as a pointer what to search for is not all that much helpful.
I might be naive, but many years of answering questions here still failed to make me jaded enough to suppose ill intentions every time. If someone writes a question i prima facie suppose s/he has already undergone some effort and came up blank - if only because s/he lacked the correct keywords to search for.
Many thanks for your consideration.
Quote:
Originally Posted by anand_bh
I will read the man page and update the result here if I found any.
You might want to concentrate on the "r" subcommand, which takes a file argument.
It will not be easy to directly replace a part of a line by the content of a file. To it seems like this is one of the very few occasions where you need to pipe the output of one sed into another. Consider the following:
inputfile:
replacementfile:
Script:
Result:
The "r" subcommand takes a file parameter and places the contents of this file into the output stream. Notice, that this is NOT a replacement! The content of the file does NOT land on the pattern space and therefore you cannot further manipulate the result.
This is why i said you might need two seds, piping the output of the first (where the file content insertion takes place) into the other (where further manipulation might take place.
Hello,
Just surfed on the web for probable answers but could not get them working.
I wish to replace the string containing spaces by another phrase but below answers did not work.
My string is:
PAIN & GAIN
I wish to convert it to:
P&G
I just need it working with sed with function -i
... (6 Replies)
Dear Unix Forum Group Members,
Please do let me know how I can replace the double pipe with single pipe recursively on single record.
Sample Input Data:
DN set|Call prefix||| Called number address nature
0||| *789|||||||ALL number types
0||| 00||||||||ALL number types
10||... (5 Replies)
Hi,
I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g.
> cat file1
banana
apple
orange
apple
banana
pear
tangerine
apple
> cat file2
I don't like apples
What would be the sed command to insert... (5 Replies)
Hello,
I have two files: file1 and file2
file1 has the following info:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2 contains an IP address (1.1.1.1)
What I want to do is replace localhost with 1.1.1.1, so that the... (4 Replies)
Hi,
I need to use the regex in the replacement string in SED command.
something like
sed -e ' s/\(^\{5\}\).\{150\}\(.*\)$/\10\{30\}1\{30\}A\{60\}B\{30\}\2/' abc
which means for all the lines in file abc that starts with 5 characters, I need to replace character 6-151... (6 Replies)
Hey everybody. I've got a simple problem but am unsure how to resolve it. I am using a script to edit multiple files at once. Inside the script I am using an sed command to make the changes. My problem is that I can only get it to work for stings that contain a word or words. How can I modify it to... (1 Reply)
Hi,
What should be the syntax to match and replace an exact string using sed? And not replacing any string that contain the value?
Eg.
testtest
etstetst
testetst
testtttt
etsttest
testtesttest
testtest
I only want to replace the line with exact string "testtest" with "123456"
... (2 Replies)
I need to search and replace a particular string in a file. Only the exact match of the string should be replaced.
eg: File contents : abc abcd abcdef
--> Replace only 'abc' with 'xyz', but it should not replace abcd with xyzd.
So the o/p should be: xyz abcd abcdef.
How can this be done? I... (5 Replies)
Hi guys, I hope you can help me with my problem.
I have a text file that contains lines like this:
78 ANGELO -809.05
79 ANGELO2 -5,000.06
I need to find all occurences of amounts that are negative and replace them with x's
78 ANGELO xxxxxxx
79... (4 Replies)