Replacing Text in Text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing Text in Text file
# 1  
Old 06-30-2008
Replacing Text in Text file

Hi Guys,

I am needing some help writing a shell script to replace the following in a text file

/opt/was/apps/was61

with some other path eg

/usr/blan/blah/blah.

I know that i can do it using sed or perl but just having difficulty writing the escape characters for it

All Help appreciated

Regards,
Chris
# 2  
Old 06-30-2008
Code:
sed 's!/opt/was/apps/was61!/usr/blan/blah/blah!'

Regards
# 3  
Old 06-30-2008
Replacing Text in Text file

sed 's!/opt/was/apps/was61!/usr/blan/blah/blah!' test.bak

Doesnt appear to work where test.bak is the file containing /opt/was/apps/was61

it spits out /usr/blan/blah/blah before the command prompt but doesnt change the file at all.

Anymore help would be much appreciated.

Regards
# 4  
Old 06-30-2008
sed doesn't change your file on the fly. use output redirection or if your sed support -i , you can use it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Programming

Replacing a word of a text file, in C++ fstream

How to replace a word in text file using c++ fstream. Is there a way, without creating any temporary file. Could you please share pseudo code ??? (1 Reply)
Discussion started by: techmonk
1 Replies

3. UNIX for Dummies Questions & Answers

Replacing all cells that have a specific value in a text file

I have a space delimited text file where I want to replace all cells that are 0 with NA. However I cannot simply use 'sed/0/NA/g' because there are other 0's in the text file that are part of numbers. Example input: 896.933464285715 0 874.691732142857 866.404660714286 Output:... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

Replacing in huge text file

I have huge text files (~120 MB)x100 which equivalents to ~11GB of data. The files contain pure numbers, actually the value of "phi" to 10 billion digits!! I know its huge!! Here are the last few lines of a file 0952899155 3233967444 3344925499 0276061529 7261968933 9683989044 3317145063... (14 Replies)
Discussion started by: shantanuthatte
14 Replies

5. UNIX for Dummies Questions & Answers

Replacing a column in a text file

Say I had a text file that contained four columns, like the following: Mack Christopher:237 Avondale Blvd:970-791-6419:S Ben Macdonor:30 Dragon Rd:647-288-6395:B I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no... (6 Replies)
Discussion started by: Sotau
6 Replies

6. UNIX for Dummies Questions & Answers

Help parsing and replacing text with file name

Hi everyone, I'm having trouble figuring this one out. I have ~100 *.fa files with multiple lines of fasta sequences like this: file1.fa >xyzsequence atcatgcacac...... ataccgagagg..... atataccagag..... >abcsequence atgagatatat..... acacacggd..... atcgaacac.... agttccagat.... The... (2 Replies)
Discussion started by: mycoguy
2 Replies

7. Shell Programming and Scripting

Replacing text in a .csv file using Perl

I have played with this for some time but i dont seem like i am getting it right. I am trying to change the delimiters on a file so i can import it into a database. this file has rows of data separated by enter Right now the delimiters are represented by tabs and " ". e.g. "dlfkldfs... (9 Replies)
Discussion started by: salemh
9 Replies

8. Shell Programming and Scripting

replacing text with contents from another file

I'm trying to change the ramfs size in kernel .config automatically. I have a ramfs_size file generated with du -s cat ramfs_size 64512 I want to replace the linux .config's ramdisk size with the above value CONFIG_BLK_DEV_RAM_SIZE=73728 Right now I'm doing something dumb like: ... (3 Replies)
Discussion started by: amoeba
3 Replies

9. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

10. Shell Programming and Scripting

replacing strings with text from other file

Hi, Im trying to update some properties files with text from another file: file1 user=xyz file2 user= after script file2 user=xyz Im using this reading the $QUARTZURL,ETC... from quartz.properties: echo... (1 Reply)
Discussion started by: mc1392
1 Replies
Login or Register to Ask a Question