LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2011, 09:16 AM   #1
rexjenny
LQ Newbie
 
Registered: Apr 2006
Posts: 18

Rep: Reputation: 0
Parsing delimited file


Advance thanks for your help. I have a tab delimited file containing the ldap username and their corresponding passwords in the following format

dn:uid=user1,o=foobar.com new_password
dn:uid=user2,o=foobar.com new_password
dn:uid=user3,o=foobar.com new_password

what i want to achieve is loop through the file and create text in the below format with a space in between them. Please help me out as am not so good with scripting. Thanks once again

dn:uid=user1,o=foobar.com
changetype:modify
replace:userpassword
userpassword:new_password

dn:uid=user2,o=foobar.com
changetype:modify
replace:userpassword
userpassword:new_password

dn:uid=user3,o=foobar.com
changetype:modify
replace:userpassword
userpassword:new_password
 
Old 07-09-2011, 09:24 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Time to learn awk!
Code:
awk -F"\t" '{ print $1; print "changetype:modify"; print "replace:userpassword"; print "userpassword:" $2; print "" }' infile > oufile
 
Old 07-09-2011, 09:33 AM   #3
rexjenny
LQ Newbie
 
Registered: Apr 2006
Posts: 18

Original Poster
Rep: Reputation: 0
Wink

Quote:
Originally Posted by colucix View Post
Time to learn awk!
Code:
awk -F"\t" '{ print $1; print "changetype:modify"; print "replace:userpassword"; print "userpassword:" $2; print "" }' infile > oufile
Geez that was a fast reply or what
Works flawlessly. Thanks a lot will start learning awk and sed as soon as i can.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rear file names to creat a comma delimited file GRS63 Linux - Software 7 02-04-2011 12:40 AM
[SOLVED] Parsing delimited file and variable scripting. mmcc0912 Linux - General 3 09-25-2010 01:49 PM
column re-alignment - space delimited to comma delimited hattori.hanzo Linux - Newbie 9 03-05-2009 12:54 AM
Parsing a tab delimited text file jajanes Programming 9 08-08-2003 10:34 AM
comma delimited file cdragon Programming 5 06-21-2002 07:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration