Find and Replace pattern in lowercase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and Replace pattern in lowercase
# 1  
Old 07-28-2010
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:

Code:
ergeAAwrgersc_DWSTAGE_AC_DBO_TBL_GROUPZONES_INITIAL.badAAergerg
sc_DWSTAGE_AC_DBO_TBL_SECTIONDEPENDENCY_INITIAL.badeAAwrgewrg
sc_DWSTAGE_AC_DBO_TBL_CONTENT_INITIAL.badewrgAAerg

Basically, the pattern is sc_DWSTAGE_.*.bad

I need to convert these to lower case ie. and remove initial and add 1 to it:

Code:
ergeAAwrgersc_dwstage_ac_dbo_tbl_groupzones1.badAAergerg
sc_dwstage_ac_dbo_tbl_sectiondependency1.badeAAwrgewrg
sc_dwstage_ac_dbo_tbl_content1.badewrgAAerg

Sed AWK?
# 2  
Old 07-28-2010
Code:
 awk 'BEGIN{FS=OFS="."}{sub(/_INITIAL/,"1",$1);t=tolower($1); print t,$2}' urfile


Last edited by rdcwayx; 07-28-2010 at 10:11 PM..
# 3  
Old 07-28-2010
Hi

Code:
sed 's/_INITIAL/1/'  file | tr '[:upper:]' '[:lower:]'

Guru.
# 4  
Old 07-28-2010
Quote:
Originally Posted by guruprasadpr
Hi

Code:
sed 's/_INITIAL/1/'  file | tr '[:upper:]' '[:lower:]'

Guru.
Other that you would have to convert back the the `AA' in places like `ergeAAwrgersc' or `badewrgAAerg' since those should stay uppercase.

Code:
sed 's/_INITIAL/1/'  file | tr '[:upper:]' '[:lower:]' | sed 's/aa/AA/g' > alfredo123wants.result

Quite convoluted!
# 5  
Old 07-30-2010
Quote:
Originally Posted by rdcwayx
Code:
 awk 'BEGIN{FS=OFS="."}{sub(/_INITIAL/,"1",$1);t=tolower($1); print t,$2}' urfile


There is no OFS..this is an xml file. I apologize I should have mentioned that before. Only the pattern that I am looking for needs to be changed to lower case atleast.

---------- Post updated at 01:18 PM ---------- Previous update was at 01:14 PM ----------

Quote:
Originally Posted by guruprasadpr
Hi

Code:
sed 's/_INITIAL/1/'  file | tr '[:upper:]' '[:lower:]'

Guru.
This changes the whole file to lower case. I only need the pattern sc_DWSTAGE_<XYZ>_INITIAL.bad to be changed to lower case: sc_dwstage_<xyz>1.bad

So for example:

sc_DWSTAGE_AC_DBO_TBL_CONTENT_INITIAL

would need to change to:
sc_dwstage_ac_dbo_tbl_content1.bad
# 6  
Old 07-31-2010
Code:
#!/bin/bash

declar -i i
i=1
while read -r LINE
do
  case "$LINE" in
     *"sc_DWSTAGE_"*)
        end="${LINE##*INITIAL}"
        front=${LINE%%sc_DWSTAGE*}
        middle="sc_DWSTAGE${LINE#*sc_DWSTAGE}"
        middle="${middle%_INITIAL*}$i"
        LINE="${front}${middle,,}${end}"
        ;;
  esac
  echo "${LINE}"
done < "file"

# 7  
Old 08-03-2010
The pattern does not exist in a line per se....it is part of the line...the problem I am having is that the pattern needs to be replaced with another pattern....The previous seems to be just putting it out to a file if i want to...

how do I replace something like

sc_DWSTAGE.*INITIAL.bad

to sc_DWSTAGE_.*1.bad where there can be more characters on the line...


so a sample line would be
<ATTRIBUTE NAME ="Reject filename" VALUE ="sc_DWSTAGE_XYZ_XYZ_XYZ_INITIAL.bad"/>

i want to replace to:
<ATTRIBUTE NAME ="Reject filename" VALUE ="sc_dwstage_xyz_xyz_xyz1.bad"/>
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

find pattern and replace the text before it

i am editing a big log file with the following pattern: Date: xxxx Updated: name Some log file text here Date: eee Updated: ny Some log file text here Basically i want to remove all the text in a line before the "Updated" pattern. I sill want to print the other... (4 Replies)
Discussion started by: balan1983a
4 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

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

8. Shell Programming and Scripting

find pattern and replace another field

HI all I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example: 100099C01101C00000000059394200701CREoperadora_TX 100099C01201C00000000000099786137OPERADORA_TX2 in the example above I need to change the first field from 1 to 2 only if... (3 Replies)
Discussion started by: sergiioo
3 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