sed and awk -Find and Replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed and awk -Find and Replace
# 1  
Old 04-04-2013
sed and awk -Find and Replace

All,

I have thousands of lines in a file with following format
Code:
DATA=_ONE_XXX_YYY_CCC_HHHG_
DATA1=_GGG_JJJJ_HHH_UUU_JJJJ_HHHH_LLL_
DATA3=_MMM_GG_NN_QQQQ_FFF_III_

I want to replace _ with . by ignoring the first (=_) and last (_)

So that out put should looks like
Code:
DATA=_ONE.XXX.YYY.CCC.HHHG_
DATA1=_GGG.JJJJ.HHH.UUU.JJJJ.HHHH.LLL_
DATA3=_MMM.GG.NN.QQQQ.FFF.III_

Can someone help on this?

Thanks
Bala

Last edited by Franklin52; 04-04-2013 at 07:09 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 04-04-2013
Please use code tags

Try this if the input file pattern is what you have mentioned
Code:
sed 's/\([A-Z]\)_\([A-Z]\)/\1.\2/g' infile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 04-04-2013
Try
Code:
$ sed -r 's:([^=])_([^$]):\1.\2:g' file
DATA=_ONE.XXX.YYY.CCC.HHHG_
DATA1=_GGG.JJJJ.HHH.UUU.JJJJ.HHHH.LLL_
DATA3=_MMM.GG.NN.QQQQ.FFF.III_

If your sed does not allow for extended regexes, replace the ( and ) by \( and \).
# 4  
Old 04-04-2013
This one is working for me...
# 5  
Old 04-04-2013
Thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace using sed

Hi All, I have a file as shown below: myFile.dat #---------------------------------------------------------- dataFile { Name shiva; location Delhi; travelID IDNumber; } 4 ( 560065 700007 100001 200002 )... (8 Replies)
Discussion started by: linuxUser_
8 Replies

2. UNIX for Dummies Questions & Answers

Sed/awk to find negative numbers and replace with 1?

Greetings. I have a three column file, and there are some numbers in the second column that are <1. However I need all numbers to be positive, thus need to replace all those numbers with just one. I feel like there must be a simple way to use awk to find these numbers and sed to replace but can't... (5 Replies)
Discussion started by: Twinklefingers
5 Replies

3. Shell Programming and Scripting

Find and replace using sed

File 1,2,33,C,B 3,5,66,K,R 1,2,33,H,M 3,5,66,M,C 6,9,66,J,F I will use the below command to find and replace in sed, where I'm using variable to find pattern. while read line do sed 's/$line/77/' file done<inputfile But here I need to find value in column 3 and... (26 Replies)
Discussion started by: Roozo
26 Replies

4. Shell Programming and Scripting

Find and Replace with sed

Hi, I have a file such that: tart*)*98'bank'ksb64bank)(tart2d&f44bank I want to replace to: (only between tart and bank) tart*)*98'replaced'ksb64bank)(tart2d&f44replaced Thanks. (6 Replies)
Discussion started by: tara123
6 Replies

5. Shell Programming and Scripting

find and replace using SED

I need to do a find and replace. I tried below logic but getting warnings Could you please help? a=`echo "<!DOCTYPE aaaaa bbbbb \"sample.dtd\">"` b="<!DOCTYPE aaaaa bbbbb \" /a/b/c/datain/d_k/sample.dtd \">" echo $a | sed -e "s/$a/$b/" > c.txt getting the following error sed:... (1 Reply)
Discussion started by: kmanivan82
1 Replies

6. Shell Programming and Scripting

find and replace with sed

Hi, I have two files file1 :> val="10" port="localhost:8080" httpadd="http:\\192.168.0.239" file2 :> val=${val} port=${port} httpadd=${httpadd} fileloc=${fileloc} file3(or file2) should have following output(input from fileone) file3 (8 Replies)
Discussion started by: nitin.pathak
8 Replies

7. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

8. Shell Programming and Scripting

Find and replace with variable using sed or awk

hi, i have file say email.temp looks like Bell_BB 17 Bell_MONTHLY 888 SOLO_UNBEATABLE 721 and another file r3 Bell BB,Bell_BB Bell,Bell_MONTHLY SOLO,SOLO_UNBEATABLE i want email.temp files $1 say Bell_BB should be replaced by r3 Bell BB and Bell_MONTHLY by... (2 Replies)
Discussion started by: raghavendra.cse
2 Replies

9. Shell Programming and Scripting

Find and replace a column that has '' to NULL in a comma delimited using awk or sed

Hi this is my first time posting ever. I'm relatively new in using AWK/SED, I've been trying many a solution. I'm trying to replace the 59th column in a file where if I encounter '' then I would like to replace it with the word NULL. example 0 , '' , '' , 0 , 195.538462 change it to 0... (5 Replies)
Discussion started by: gumal901
5 Replies

10. Shell Programming and Scripting

[sed/awk] find info and replace

Hi :) I have some problems with "FOR"... I have a text file in this format: name1 www.link1/random_number name2 www.link2/random_number name3 www.link3/random_number ... (Names and info changes) Now, I need: (4 Replies)
Discussion started by: aspire
4 Replies
Login or Register to Ask a Question