Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change particular data in a large file 2

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
US
I have some data in a file which looks like this.

<Attribute name='mname' type='string' value='X.'/>
<Attribute name='ssn id' type='string' value='111111111'/>
<Attribute name='org' type='string' value='Top:XXXXXX:NAM:TBD'/>
<Attribute name='origin' type='string' value='XXXX'/>
<Attribute name='sDate' type='string' value='02/19/2005'/>

The above data is from one record.

I need to read the data in this file and find the 'ssn id' Then I need to change the value of 'ssn id' (111111111 in the above record) to some other number(e.g., a random 9 digit number or some default 9 digit number for all the records in the file).

This needs to happen throughout the file for all the records.

How do I achieve this?

Thanks,
Pramod
 
Does each random number have to be unique? if so how many lines are we talking?



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
mrn,
The numbers have to be unique and also a 9 digit number. There are around 100000 records.

Feherke,
Your solution does work but does not provide the output I am looking for(I was not clear enough in the requirements). The generated ssn id needs to be a 9 digit number(The solution generates a 1 digit number). Also sometimes the ssn id values could be something like DF643367G(This case the solution does not work)

mrn and Feherke,
Other thing we can do is wherever we find ssn id - change the value to some default number e.g., 9999999999. Thus throughout the file the ssn id will be '9999999999'.

The whole point of this exercise is that we do not want to give out the real ssn's to the customers. We need to change the values(to different unique values based on the current values or to some default number) before sending out the file.

Thanks,
Pramod
 
You should be able to use SED for this. create a file eg tom.sed with the following (all on one line) :-

s^'ssn id' type='string' value='111111111'/^'ssn id' type='string' value='999999999'/^g

Next run sed -ftom.sed 'your_input_file'
 
Hi

taupirho gave me another idea. If all snn ids are nine character long, are unique and needs to be consistent, then one easy way would be to shuffle the digits :
Code:
sed "/name='ssn id'/s/value='\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'/value='\2\4\6\8\9\7\5\3\1'/g" /input/file

[gray]# or more readable fot GNU sed[/gray]

sed -r "/name='ssn id'/s/value='(.)(.)(.)(.)(.)(.)(.)(.)(.)'/value='\2\4\6\8\9\7\5\3\1'/g"

Feherke.
 
Good idea Feherke, however OP needs to clarify his data format. In the OP he/she says that the data shown is from one record. Do they also mean that the data in on one line? if so there would be multiple "value=" strings and your sed command would not provide the output required.
 
I have posted 5 records from my file. If you see closely the ssn id is present at two places in each record. The ssn id is unique and will not be repeated in any other record. I need to change the ssn id at both places in each record. I hope I am clear enough this time.

Thanks,
Pramod



<!-- MemberObjectGroups="#ID#XXXX:DIS:NAM" cost="11111" costDescription="Home Loans" employeeStatus="J" employeeType="D" firstname="John" fullname="John D Simmer" jobCode="UNH5535" ssn id="111111111" origin="USA" prov="5" res="#ID#FG794GD55B732D35D5:1DE4A4:102D4C1372GG:-6SS4" startDate="02/13/2003" tedsDN="HD=KJDK347,OU=NAM,O=DIS"-->
<Attribute name='ssn id' type='string' value='111111111'/>

<!-- MemberObjectGroups="#ID#XXXX:DIS:NAM" cost="11111" costDescription="Home Loans" employeeStatus="J" employeeType="D" firstname="John" fullname="John D Simmer" jobCode="UNH5535" ssn id="456372828" origin="USA" prov="5" res="#ID#FG794GD55B732D35D5:1DE4A4:102D4C1372GG:-6SS4" startDate="02/13/2003" tedsDN="HD=KJDK347,OU=NAM,O=DIS"-->
<Attribute name='ssn id' type='string' value='456372828'/>

<!-- MemberObjectGroups="#ID#XXXX:DIS:NAM" cost="11111" costDescription="Home Loans" employeeStatus="J" employeeType="D" firstname="John" fullname="John D Simmer" jobCode="UNH5535" ssn id="FH647383J" origin="USA" prov="5" res="#ID#FG794GD55B732D35D5:1DE4A4:102D4C1372GG:-6SS4" startDate="02/13/2003" tedsDN="HD=KJDK347,OU=NAM,O=DIS"-->
<Attribute name='ssn id' type='string' value='FH647383J'/>

<!-- MemberObjectGroups="#ID#XXXX:DIS:NAM" cost="11111" costDescription="Home Loans" employeeStatus="J" employeeType="D" firstname="John" fullname="John D Simmer" jobCode="UNH5535" ssn id="KF478329D" origin="USA" prov="5" res="#ID#FG794GD55B732D35D5:1DE4A4:102D4C1372GG:-6SS4" startDate="02/13/2003" tedsDN="HD=KJDK347,OU=NAM,O=DIS"-->
<Attribute name='ssn id' type='string' value='KF478329D'/>

<!-- MemberObjectGroups="#ID#XXXX:DIS:NAM" cost="11111" costDescription="Home Loans" employeeStatus="J" employeeType="D" firstname="John" fullname="John D Simmer" jobCode="UNH5535" ssn id="356272819" origin="USA" prov="5" res="#ID#FG794GD55B732D35D5:1DE4A4:102D4C1372GG:-6SS4" startDate="02/13/2003" tedsDN="HD=KJDK347,OU=NAM,O=DIS"-->
<Attribute name='ssn id' type='string' value='356272819'/>
 
OK, your tom.sed should now like like (2 lines):-

s^'ssn id' type='string' value='111111111'/^'ssn id' type='string' value='999999999'/^g
s^ssn id="111111111"^ssn id="999999999""^g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top