Find and replace pattern in VI editor


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and replace pattern in VI editor
# 1  
Old 09-07-2009
Find and replace pattern in VI editor

All,
I have a text file which has the following data
X_SQL_13,X_SQL_14,X_SQL_15,X_SQL_16,X_SQL_17,X_SQL_18,X_SQL_19,X_SQL_20,X_SQL_21,X_SQL_22,X_SQL_23,X _SQL_24,X_SQL_25,X_SQL_26,X_SQL_27,
X_SQL_28,X_SQL_29,X_SQL_30,C_TYPE_GNRT,F_TRACE_SQL,X_PARAM_1,X_PARAM_2,X_PARAM_3,X_PARAM_4,X_PARAM_5 ,X_MSG_PARAM_1,X_MSG_PARAM_2,
X_MSG_PARAM_3,X_MSG_PARAM_4,X_MSG_PARAM_5,C_TYPE_SQL) values ('ECP','TVP404100','select * from (select
(D_PROC) D_PROC
,ORG,LOGO
,REC_NBR
,R SEQ,decode ( r,1 ,MESSAGE_LINE_1,
2 ,MESSAGE_LINE_2,
3 ,MESSAGE_LINE_3,
4 ,MESSAGE_LINE_4,
5 ,MESSAGE_LINE_5,
6 ,MESSAGE_LINE_6,
7 ,MESSAGE_LINE_7,
8 ,MESSAGE_LINE_8,
9 ,MESSAGE_LINE_9,
10 ,MESSAGE_LINE_10,
11 ,MESSAGE_LINE_11,
12 ,MESSAGE_LINE_12,
13 ,MESSAGE_LINE_13,
14 ,MESSAGE_LINE_14,
15 ,MESSAGE_LINE_15,
16 ,MESSAGE_LINE_16,
........................
......................


Can any one please tell me how to relace MESSAGE_LINE_1 to MESSAGE_LINE_16 with MESSAGE_LINE_1_1 to MESSAGE_LINE_16_1

I was using :%s/MESSAGE_LINE_16/MESSAGE_LINE_16_1/ in the VI editor
But I want something as as

:%s/MESSAGE_LINE_*/MESSAGE_LINE_*_1/

thanks
# 2  
Old 09-07-2009
please delete this
# 3  
Old 09-07-2009
Code:
:%s/,$/_1,/g

# 4  
Old 09-07-2009
With sed...
Code:
 
sed 's/\(MESSAGE_LINE_[0-9].*\)\(,.*\)/\1_1\2/g' infile

# 5  
Old 09-07-2009
Code:
:g/MESSAGE_LINE/s/_\([0-9]*\),/_\1_1,/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find pattern and replace using sed

Hi, i want to replace the following lines in such a way that if the word merge exists in first column it must replace the 3rd column as M and if parse exists in first column then the last column must P, if neither it must mark it as X. I have tried the solution using awk, but it is saying... (6 Replies)
Discussion started by: charlie87
6 Replies

2. Shell Programming and Scripting

Search pattern then find and replace

If condition satisfy, want to find pattern and modify two Fields in Modify.txt Input.txt SOURCE1 SOURCE2 SOURCE3 SOURCE4 SOURCE5 SOURCE6 Modify.txt SOURCE1|SLA|2016/12/11 11:12:11 PM|HMM|11-11-16| SOURCE2|SLA|2016/13/11 11:12:11 PM|HMM|10-11-16| SOURCE3|SLA|2016/14/11 11:12:11... (7 Replies)
Discussion started by: Joselouis
7 Replies

3. Shell Programming and Scripting

Find and Replace Pattern in file

Ok, so how many times have you received this request? I have been looking through the forum for examples and I see the use of tr, awk and sed to perform similar functions but not sure how to use the tools in this scenario and could use a push in the right direction. GOAL: Search for line... (9 Replies)
Discussion started by: djzah
9 Replies

4. Shell Programming and Scripting

sed find/replace a pattern, but not this one..

I've got a file like so: ...lots of lines, etc. push "route 10.8.0.0 255.255.255.0" push "route 192.168.1.123 255.255.255.0" ...lots of lines, etc. I want to sed find/replace the IP address in the second line, whatever it is, with a new IP address, but I don't want to touch the first line.... (5 Replies)
Discussion started by: DaHai
5 Replies

5. Shell Programming and Scripting

Help to find two pattern in vi editor

I want to find two pattern in vi editor.for example in file demo.txt I want to find a record such as "BDBO" and "sh". how can i find such a record bu using single command in demo.txt in vi editor. please help. ---------- Post updated at 01:49 AM ---------- Previous update was at 01:46 AM... (5 Replies)
Discussion started by: ashfaque
5 Replies

6. Shell Programming and Scripting

Find and Replace pattern in lowercase

I have an xml file. I need to convert a particular pattern to lower case and add 1 to it. For example my sample values in file are: ergeAAwrgersc_DWSTAGE_AC_DBO_TBL_GROUPZONES_INITIAL.badAAergerg sc_DWSTAGE_AC_DBO_TBL_SECTIONDEPENDENCY_INITIAL.badeAAwrgewrg... (6 Replies)
Discussion started by: alfredo123
6 Replies

7. Shell Programming and Scripting

find a pattern and replace

i have a file which contains lines like this. intsrcrpttrn1099mctrl:export GRAPHPARM_AR="-input_code M302023" intsrcrpttrn1099mload:export GRAPHPARM_AR="-input_code M192023" intsrcrpttrn1099mload:export GRAPHPARM_AR="-input_code P192023" the value after -input_code starts with some alphabet... (4 Replies)
Discussion started by: dr46014
4 Replies

8. Shell Programming and Scripting

Find a pattern and replace using sed.

Hi I need to help on finding the below pattern using sed <b><a href="/home/document.do?assetkey=x-y-abcde-1&searchclause=photo"> and replace as below in the same line on the index file. <b><a href="/abcde.html"> thx in advance. Mari (5 Replies)
Discussion started by: maridhasan
5 Replies

9. Shell Programming and Scripting

find and replace a pattern in a file

Hi I am having 2 files file1.c and file2.c Now i want to find all the occurances of pattern "abc" in file1.c, file2.c and replace with pattern "def" using shell script without using sed and with using sed. Thanks in advance... raju (1 Reply)
Discussion started by: krishnamaraju
1 Replies

10. UNIX for Dummies Questions & Answers

find pattern in FILES and replace it ??

Hi How can I looking for a pattern found in more than one file and replace it with anther pattern this what I was used: find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \; this print the files name -which is account.adrs- and its path -which is deferent for each... (4 Replies)
Discussion started by: tamer
4 Replies
Login or Register to Ask a Question