Double grep and replacing

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Double grep and replacing
# 1  
Old 04-06-2017
Double grep and replacing

Hi All,

I need to replace a match with are new values when there is a double match.


Code:
grep 04422494 MAX.dat | grep 1102300131

I need to replace 1102300131 as 1101600131 in MAX.dat only for the record matching 04422494 . I tried replace as

Code:
sed/s/1102300131 /1101600131 /g MAX.dat

but it replace all records including 04422494 and other records.


Can you please help

Thanks
Arun
# 2  
Old 04-06-2017
having a sample input and desired output would help....
# 3  
Old 04-06-2017
Below is the example

sample input
Code:
000442249411023001312016031500000000000000001872000000000000000
000442249411023001312016032100000000000000001872000000000000000
000442249411023001312016032100000000000000001872000000000000000
000442249411023001312016033100000000000000001872000000000000000
000442249511023001312016031500000000000000001872000000000000000
000442249511023001312016032100000000000000001872000000000000000
000442249611023001312016032100000000000000001872000000000000000
000442249611023001312016033100000000000000001872000000000000000

desired output
Code:
000442249411016001312016031500000000000000001872000000000000000
000442249411016001312016032100000000000000001872000000000000000
000442249411016001312016032100000000000000001872000000000000000
000442249411016001312016033100000000000000001872000000000000000
000442249511023001312016031500000000000000001872000000000000000
000442249511023001312016032100000000000000001872000000000000000
000442249611023001312016032100000000000000001872000000000000000
000442249611023001312016033100000000000000001872000000000000000


Last edited by Scrutinizer; 04-06-2017 at 04:38 PM.. Reason: Quote tags => code tags
# 4  
Old 04-06-2017
Try:

Code:
sed 's/^\(0004422494\)1102300131/\11101600131/' file

or, a less accurate but maybe good enough:
Code:
sed '/04422494/s/1102300131/1101600131/' file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

2. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

3. UNIX for Dummies Questions & Answers

Grep and replacing with ..

Hi I'm trying trying to replace '~/Documents/research/racedata' with '..' in all files in a directory. What is the best way I should go about this? Thanks. (4 Replies)
Discussion started by: Jane Yi
4 Replies

4. Shell Programming and Scripting

Double Grep Count

Hi Friends, I want to find all processes beginning with the name 'Admin' and then do a grep count on those processes containing a specific string i.e. However, it is giving below error ps -ef | grep ^Admin | grep -ic 'Jan' -e 'Feb' -e 'Mar' grep: Jan: No such file or directory ... (4 Replies)
Discussion started by: srkmish
4 Replies

5. Shell Programming and Scripting

Replacing double quotes with the unicodes "urgent!"

Hi, I have the following text in a file <div class="snippet abstract"> We present a new "model" for multiple-input-multiple-output (MIMO) 'outdoor' has many things "what" ever </div></a href=sdfkkf"> </div> <div class="snippet context"> I have to replace the string between the <div... (1 Reply)
Discussion started by: vms
1 Replies

6. UNIX for Dummies Questions & Answers

Replacing double spaces with single space

I am looking for a regular expression that uses sed to replace multiple spaces with single spaces on every line where it is not at the start of the line and not immediately before double slashes ('//') or between quotes ("). In its simplest form, it would look like this: sed -e 's# # #g'... (4 Replies)
Discussion started by: figaro
4 Replies

7. Shell Programming and Scripting

Replacing grep with awk

how to replace grep with awk commands. i have a code like: grep -w $student $markfile|$subjectid can similar code be written by replacing grep with awk. Thanks in advance, regards, giri (6 Replies)
Discussion started by: girijan
6 Replies

8. UNIX for Dummies Questions & Answers

Replacing grep with awk

This may be a repetitive or simple question, but I have a long running code, which uses a grep with a big argument, and i was wondering if there was a way to replace all of my greps with awk....here are my two commands using greps. x=$(ls /my/directory/here | grep -h ".$variable") and ... (1 Reply)
Discussion started by: jgrosecl
1 Replies

9. Shell Programming and Scripting

Replacing comma with in double quotes in a csv file

Hello, I need to read a csv file and I am trying to replace a comma with a text DSEE?DSEE. Example Input "Chapter","NewTrains, "oldTrains","Delayed",10,"London" "Chapter","Newbuses,oldbuses","On Time",20,"London" Output "Chapter","NewTrainsDSEE?DSEE... (5 Replies)
Discussion started by: venkatvani
5 Replies

10. Shell Programming and Scripting

Replacing the string after certain # of double quote

Could you please help in unix scripting for below scenario... In my input file, there might be a chance of having a string ( Ex:"99999") after 5th double quote for each record. I need to replace it with a space. Ex : Input : "abcdef","12345","99999","0986"... (3 Replies)
Discussion started by: vsairam
3 Replies
Login or Register to Ask a Question