Find and replace data in text file with data in same file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and replace data in text file with data in same file
# 1  
Old 12-09-2009
Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with.

I am trying to format an ldif file so I can import it into Oracle oid.

I need the file to look like this example. Keep in mind there are 3000 of these in the file.

Code:
 
changetype: modify
replace: userpassword 
dn: cn=4448322,cn=Users,dc=bennettware,dc=com
userpassword: {SHA}r+uU3mySUIISdVdTDvQxPRLdBFj5w=
-
replace: passwordexpiretime
passwordexpiretime: 20091031112231
-
replace: orclpassword
orclpassword: {x- orcldbpwd}1.0:83sdfdf24977D14AA
 
changetype: modify
replace: userpassword 
dn: cn=213333,cn=Users,dc=bennettware,dc=com
userpassword: {SHA}r+ukljasdfl;kjafdVdTDvQxPRLdBFj5w=
-
replace: passwordexpiretime
passwordexpiretime: 20091031112231
-
replace: orclpassword
orclpassword: {x- orcldbpwd}1.0:835sdff4977D14AA

I have it to this point. Please keep in mind sometimes the userpassword: encrypted pass is in different places in the string of each user. Notice the userpassword: enc pass is not under the dn: line.

Code:
changetype: modify
replace: userpassword
dn: cn=418322,cn=Users,dc=bennettware,dc=com
-
replace: orclpassword
userpassword: {SHA}B6UenM9qwerwerews3V5ve8H3H0=
orclpassword: {x- orcldbpwd}1.0:8359A824977D14AA
-
replace: passwordexpiretime
passwordexpiretime: 20091031112231

The long and short is I need to move the "userpassword: encryptep pass" up to directly under the dn field for each record. Is there anyway I can do this with awk or sed or something.

Any help would be greatly appreciated.

Tim

---------- Post updated at 03:28 PM ---------- Previous update was at 09:49 AM ----------

I found a work around.

Thanks for the consideration.

Tim

Last edited by zaxxon; 12-09-2009 at 10:50 AM.. Reason: code tags please
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to find data in three file and perform replace operation

Have three files. Any other approach with regards to file concatenation or splitting, etc is appreciated If column55(billngtype) of file1 contains YMNC or YPBC then pick the value of column13(documentnumber). Now find this documentnumber in column1(Billdoc) of file2 and grep the corresponding... (4 Replies)
Discussion started by: as7951
4 Replies

2. Shell Programming and Scripting

Modifying text file records, find data in one place in the record and print it elsewhere

Hello, I have some text data that is in the form of multi-line records. Each record ends with the string $$$$ and the next record starts on the next line. RDKit 2D 15 14 0 0 0 0 0 0 0 0999 V2000 5.4596 2.1267 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 ... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

5. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

6. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

7. Shell Programming and Scripting

find string(s) in text file and nearby data, export to list help

Hi, So I'm kinda new to shell scripts and the like. I've picked up quite a bit of use from browsing the forums here but ran into a new one that I can't seem to find an answer for. I'm looking to parse/find a string AND the next 15 or so charachters that follow the string within a text file... (1 Reply)
Discussion started by: kar23me
1 Replies

8. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

9. Shell Programming and Scripting

Find lines in text file with certain data in first field

Hi all, Sorry for the title, I was unsure how to word my issue. I'll get right to the issue. In my text file, I need to find all lines with the same data in the first field. Then I need to create a file with the matching lines merged into one. So my original file will look something like... (4 Replies)
Discussion started by: rstev39147
4 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question