[Solved] sed to replace words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] sed to replace words
# 1  
Old 08-23-2013
[Solved] sed to replace words

Hello All,


I have file named filelist.txt

a.bteq.ctl
b.bteq.ctl
c.bteq.ctl

I want to replace the word bteq to tpt in this file.

I used this sed command
Code:
 cat filelist.txt | sed 's/bteq/tpt/g'  > filelist.txt

But this command deletes all records from the filelist.txt

Can anybody please point out what is the problem with above command
# 2  
Old 08-23-2013
If you read from a file and write to it at the same time, all you get is a corrupted file.
sed has options for in-file editing --> the -i switch

Code:
sed -i.bak 's/bteq/tpt/g' filelist.txt

Now you have the original file as filelist.txt.bak and the edited file filelist.txt
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 08-23-2013
Thanks,

Worked like a charm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

sed Find and Replace Text Between Two Strings or Words

I am looking for a sed in which I can recognize all of the text in between two indicators and then replace it with a place holder. For instance, the 1st indicator is a list of words "no|noone|havent" and the 2nd indicator is a list of punctuation ".|,|!".From a sentence such as "noone... (3 Replies)
Discussion started by: owwow14
3 Replies

3. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

4. Shell Programming and Scripting

[Solved] sed - how replace date in script

Hi All, I have a requirement to find and replace old date with new date value. Below is the scenario: # In the input file, date is MM/DD/YYYY format PREV_DTE=09/15/2013 I want to replace with 09/30/2013. It should look like PREV_DTE=09/30/2013 I am using below sed command :... (4 Replies)
Discussion started by: rockygsd
4 Replies

5. Shell Programming and Scripting

[Solved] sed : last character replace

Hi all , I have to write a shell script that takes a number as input , like 123 and the output will be 6 ,i.e the output will be the sum of digits of the input. I have an idea as follows, echo "123"|fold -1|tr '\n' '+'|bc But the problem is after " echo "123"|fold -1|tr '\n' '+' "... (5 Replies)
Discussion started by: M.Choudhury
5 Replies

6. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Vi - replace words with points (.)

Hello guys, I'm trying to replace the word "i.e." for "ie." in Vi but everytime I used the search tool for start looking for it (this is: /i.e.), it finds every word that contains the "i" and "e" word. I tried the following command: :%s/i.e./ie./g However, it doesn't work. Any help... (2 Replies)
Discussion started by: Gery
2 Replies

8. Shell Programming and Scripting

Solved - Sed - Positional Replace

Hi All, I don't know what I am doing wrong in the regex below. I have the following string: 31000000010201005181121360000000100000000003000000YYY-YYY-YYY-20100518-104139.txt.YYY I need to split it in parts: - Group 1: 3100000001020100518112136 - Group 2: 000000010 - Group 3:... (0 Replies)
Discussion started by: felipe.vinturin
0 Replies

9. UNIX for Dummies Questions & Answers

replace words in sed using regular expression

hi, I need to replace all these lines from my text file 123end 234end 324end 234end 989end 258end 924end At the moment I know how to replace "end". But I want to replace the numbers before end as well. How can I do this ? sed s/end/newWord/ myfile.txt newFile.txt thanks (3 Replies)
Discussion started by: aneuryzma
3 Replies

10. UNIX for Dummies Questions & Answers

sed replace words in file and keep some

lets see if i can explain this in a good way. im trying to replace some words in a file but i need to know what the words are that is beeing replaced. not sure if sed can do this. file.name.something.1DATA01.something.whatever sed "s/./.DATA?????/g" need to know what the first . is... (2 Replies)
Discussion started by: cas
2 Replies
Login or Register to Ask a Question