Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
TetraWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Upcctns script to replace a entry in ldif file
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Scenario : There were two files("test", "test.ldif"), in 1st file("test") there were two fields, one field contained a numeric value(i.e. 772760042) and other field contained a string value(i.e. test str). In the 2nd file("test.ldif") there was a entry like "cn: 772760042". "test" file:- ----------------------------------------------- 772760042, test str ----------------------------------------------- "test.ldif" file:- ------------------------------------------------------------------------ dn: uid=772760042,ou=upcctns.gov.in,dc=upcctns,dc=gov,dc=in objectClass: top objectClass: inetOrgPerson objectClass: qmailUser cn: 772760042 <--- sn: 772760042 mail: 772760042@upcctns.gov.in accountStatus: active mailMessageStore: upcctns.gov.in/772760042 uid: 772760042 mailHost: mail.upcctns.gov.in deliveryMode: noforward ------------------------------------------------------------------------ What was needed is we had to read the numeric value(i.e. 772760042) from 1st file("test") and search it in the 2nd file("test.ldif") and then replace the entry("cn: 772760042") with the 2nd field("test str") from 1st file("test") After running the script the "test.ldif" file should look like ------------------------------------------------------------------------ dn: uid=772760042,ou=upcctns.gov.in,dc=upcctns,dc=gov,dc=in objectClass: top objectClass: inetOrgPerson objectClass: qmailUser cn: test str <--- sn: 772760042 mail: 772760042@upcctns.gov.in accountStatus: active mailMessageStore: upcctns.gov.in/772760042 uid: 772760042 mailHost: mail.upcctns.gov.in deliveryMode: noforward -------------------------------------------------------------------------- Script:- #!/bin/bash INPUT_FILE=/home/tetra/Downloads/rakesh/test OUTPUT_FILE=/home/tetra/Downloads/rakesh/test.ldif #count=1 while IFS=, read -r f1 f2 do #echo "cn: $f1" "cn: $f2" #echo $count pass #count=$(( $count + 1 )) awk -v old="cn: $f1" -v new="cn: $f2" '{ sub(old,new); print $0 }' "$OUTPUT_FILE" > ex cat ex > "$OUTPUT_FILE" done < $INPUT_FILE
Summary:
Please note that all contributions to TetraWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TetraWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)