How to replace the string in unix file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to replace the string in unix file?
# 1  
Old 06-26-2007
MySQL How to replace the string in unix file?

Hi

Am getting "Line too long" error in opening a file using vi editor but it is opening using cat.

How can i edit the file to replace some string in it.


Thanks
# 2  
Old 06-26-2007
use sed / perl - that should be quite easier if you are not able to edit the file in place


could you post some examples on what need to be done ? Smilie
# 3  
Old 06-26-2007
Thanks for your reply.

When am using sed, the command is not replacing the string.
sed -e 's/notes2/notes/g' expoutnotesall > outfile
I used ed in HOME argument format also in scrip as

ed $1 <<-EOT
1,\$s/notes2/notes/g
w
q
EOT


Can u tell me exactly how to use sed /perl here in shell scripts.
# 4  
Old 06-26-2007
Param,
As Matrixmadhan said, could you post a sample of your input
and expected output?
# 5  
Old 06-26-2007
sorry, i cant give the contnent of input file.
This file contains the string "notes2" which has to be replaced by the string "notes".

Since i was not able to open in vi editor, i cant give the input file.
It is an export file produced by some command in our application which is in data file format. Using cat command i was able to view the file content.
# 6  
Old 06-26-2007
Quote:
Originally Posted by param_it
sorry, i cant give the contnent of input file.
This file contains the string "notes2" which has to be replaced by the string "notes".

Since i was not able to open in vi editor, i cant give the input file.
It is an export file produced by some command in our application which is in data file format. Using cat command i was able to view the file content.
Use fold command to cut the text in your file into multiple lines with 80 characters per line
Code:
fold -80 filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

3. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

4. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

5. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

8. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

9. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies
Login or Register to Ask a Question