File Processing - How to Replace particular record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Processing - How to Replace particular record
# 1  
Old 09-22-2011
Question File Processing - How to Replace particular record

I have a file with data as

Code:
1                             
L                             
1                             
Used                          
1                             
1                             
1                             
1                             
L                             
1                             
L                             
1                             
Véhicule d’occasion           
1                             
1                             
1                             
1                             
1                             
Véhicule d’occasion           
1                             
1                             
1                             
Used                          
1                             
Used                          
1                             
1                             
1                             
1                             
1                             
1                             
Véhicule d’occasion           
1                             
1                             
1                             
Véhicule d’occasion           
Véhicule d’occasion           
Véhicule d’occasion           
Véhicule d’occasion           
L

I have to replace the rows having Véhicule d’occasion with abc123 with out effectiong the other records.

Thanks!!!
# 2  
Old 09-22-2011
Code:
$ sed "s,\'occasion,occasion,g" infile

# 3  
Old 09-22-2011
Quote:
Originally Posted by jayan_jay
Code:
$ sed "s,\'occasion,occasion,g" infile

Not working!!!
# 4  
Old 09-22-2011
previously you were given a different pattern for replacement .. have you changed it ?? anyway below the code for current requirement..
Code:
$ sed "s,Véhiculed\'occasion,abc123,g" infile

# 5  
Old 09-22-2011
Question

Quote:
Originally Posted by jayan_jay
previously you were given a different pattern for replacement .. have you changed it ?? anyway below the code for current requirement..
Code:
$ sed "s,Véhiculed\'occasion,abc123,g" infile

Its not working again, may be there are any spl characters & white space at the End.

Onething can we do the same for records starts with V

i.e; like V*

???

Thanks!!!
# 6  
Old 09-22-2011
instead of "*" , try with "." .. This works for me ..
Code:
$ sed "s,V.hicule d.occasion,abc123,g" infile
1
L
1
Used
1
1
1
1
L
1
L
1
abc123
1
1
1
1
1
abc123
1
1
1
Used
1
Used
1
1
1
1
1
1
abc123
1
1
1
abc123
abc123
abc123
abc123
L
$

This User Gave Thanks to jayan_jay For This Post:
# 7  
Old 09-22-2011
Thanks man.... Its working.
I will update if at any case, it fails.

Thanks!!! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string for every record after the 1st record

I have data coming in the below format for each record <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><testdetials>....</test_sox> <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox... (8 Replies)
Discussion started by: dsravanam
8 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

4. Shell Programming and Scripting

Replace field in one file with whole record data of another

Hello Group, I need to replace the city field in “File 1 (fileld 3), with the entire record line of “File 2” (including delimiters) where the “city” field (File 1, Field 3)matches city field (File 2, Field1). All of the other data in “File 1” should remain intact(Fields 1,2,4,5,6). Only field... (1 Reply)
Discussion started by: vestport
1 Replies

5. Shell Programming and Scripting

Help with File processing - Adding predefined text to particular record based on condition

I am generating a output: Name Count_1 Count_2 abc 12 12 def 15 14 ghi 16 16 jkl 18 18 mno 7 5 I am sending the output in html email, I want to add the code: <font color="red"> NAME COLUMN record </font> for the Name... (8 Replies)
Discussion started by: karumudi7
8 Replies

6. Shell Programming and Scripting

Testing Next Record before processing is done on that Record

I am trying to see if there is a way in awk to test the next record before processing. All I am trying to do is see if the next line equal something then turn a flag off. Example: Problem Cron IneedThis KeyOnThis somemoredata somemoredata Cron somemoredata somemoredata IneedThis... (7 Replies)
Discussion started by: timj123
7 Replies

7. Shell Programming and Scripting

search and replace fixed length record file

Hi I need to be search a file of fixed length records and when I hit a particular record that match a search string, substitute a known position field In the example file below FHEAD000000000120090806143011 THEAD0000000002Y0000000012 P00000000000000001234 TTAIL0000000003... (0 Replies)
Discussion started by: nedkelly007
0 Replies

8. Shell Programming and Scripting

Replace third field of the first record in a file....

Hi, I am new to unix and am trying to do something below: I have a pipe delimited file with millions of records. I need to replace the third column of the first record to the number of lines in the file. How can I do that. Will appreciate any advice and help. Thanks Simi (3 Replies)
Discussion started by: simi28
3 Replies

9. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

10. Shell Programming and Scripting

how to replace field for each record

Hello, I have the following xml formatted file. I would like to get the newnumber field number and replace into customernumber for each record. For example: <XMLFORMAT> <customernumberR11>9</customernumberR11> ... (12 Replies)
Discussion started by: happyv
12 Replies
Login or Register to Ask a Question