how to find the pattern inside the file and replace it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find the pattern inside the file and replace it
# 1  
Old 08-11-2010
how to find the pattern inside the file and replace it

hello everybody,
I have a group of file
eg-
Code:
    sample1
    sample2 
    sample3
    sample4

each file contain this :-
Code:
cat sample1
SEQ_NUM,1,UPESI1

My requirement is to
change the value-UPESI1 to UPE10 in file which contain this pattern -UPESI1.

any help is appreciated.

Moderator's Comments:
Mod Comment Start using code tags, ty.
# 2  
Old 08-11-2010
Do a test like this to see if the output is what you expect and no unexpected changes are made:
Code:
sed 's/,UPESI1/,UPE10/' sample1 | less

When you are sure it's right (e.g. did you want a leading dash or not), change one file like this (-i is for change it in place):
Code:
sed -i 's/,UPESI1/,UPE10/' sample1

Or do them all
Code:
sed -i 's/,UPESI1/,UPE10/' sample*

# 3  
Old 08-11-2010
find . -name sample* | xargs perl -pi -e 's/UPESI1/UPE10/g'
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 all .sh files in file system and need to replace the string inside .sh files

Hi All, I need to write a script to find all "*.sh" files in /home file system and if any string find "*.sh" files with the name vijay@gmail.com need to replace with vijay.bhaskar@gmail.com. I just understood about the find the command to search .sh files. Please help me on this. find / -name... (3 Replies)
Discussion started by: bhas85
3 Replies

2. 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

3. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

4. UNIX for Dummies Questions & Answers

Find a value inside file1 and replace it with another value from another fileB

i have a file with some data and i need replace a perticular value with some other value from another another file req: file1.txt abc,idle.txt,1234 file2.txt 5678 now the requirement is need to replace the "idle.txt" is with "mike_5678" here 5678 from file2.txt... file2.txt contains only... (2 Replies)
Discussion started by: dssyadav
2 Replies

5. 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

6. 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

7. Shell Programming and Scripting

pattern replace inside text file using sed

Hi, I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file. For Example: If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained. But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Discussion started by: meharo
4 Replies

8. Shell Programming and Scripting

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,... (4 Replies)
Discussion started by: thana
4 Replies

9. Shell Programming and Scripting

Error: Find the pattern in the file and replace

Hi all, I have requirement where i need to find a pattern and replace it by new word. I used the below perl command echo `perl -p -i -e "s/AbCdEf/PqRsTu/g;" FileName.txt` But I am getting an error as below Can't do inplace edit Not a Owner and the file FileName.txt gets ... (9 Replies)
Discussion started by: shreekrishnagd
9 Replies

10. 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
Login or Register to Ask a Question