The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 08:29 AM
Insert a line aajan UNIX for Advanced & Expert Users 5 08-20-2007 01:49 AM
how to insert a line number on every line mopimp UNIX for Dummies Questions & Answers 3 03-25-2006 01:35 PM
insert a line in a file RishiPahuja Shell Programming and Scripting 7 06-22-2005 03:47 AM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-09-2005 01:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-21-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
insert a line after specific line

Hii,

I have a file like this--
Quote:
dn: cn=Anandmohan Singh,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Anandmohan Singh
givenName: Anandmohan
mail: anand_ms@thbs.com
mobile: 9986010455
o: Torry Harris
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Singh
telephoneNumber: 41827200 Extn: 7400
title: Associate Software Engineer - Trainee
uid: 1432

dn: cn=Riteshkumar Mohanty,ou=addressbook,dc=thbs,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Riteshkumar Mohanty
givenName: Riteshkumar
mail: ritesh_m@thbs.com
mobile: 9916953109
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Mohanty
telephoneNumber: 41827200 Extn: 7400
title: Associate Software Engineer - Trainee
uid: 1418
Here i want to replace the line o: Torry Harris with o: Torry arris Business Solutions and in file there are places where this line is not there after the Mobile number,so i want to insert the line as --o: Torry arris Business Solutions. i can replace it easily with sed but how i can insert the line after that.

Thanks
  #2 (permalink)  
Old 05-21-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
Try using VI for this.


vi commands
  #3 (permalink)  
Old 05-21-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi,

if input is

givenName: Anandmohan
mail: anand_ms@thbs.com
mobile: 9986010455
o: Torry Harris
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Singh

o/p should be

givenName: Anandmohan
mail: anand_ms@thbs.com
mobile: 9986010455
--o: Torry arris Business Solutions
ou: null
physicalDeliveryOfficeName: ST-6th Floor
sn: Singh

Am I Right. If not send a sample output

Thanks
Penchal
  #4 (permalink)  
Old 05-21-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
This file is very big infact, if i start doing it with VI it will consume plenty of time.
Yes penchal u r right about the output,one more thing there are places after mobile number where the line is not there we need to insert the line there.

Thanks
  #5 (permalink)  
Old 05-21-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Try this:

Code:
awk '/^mobile: /{
print; getline; print "o: Torry arris Business Solutions"
if(substr($1,1,2) == "o:"){next}
}1' file
Regards
  #6 (permalink)  
Old 05-21-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by Franklin52 View Post
Try this:

Code:
awk '/^mobile: /{
print; getline; print "o: Torry arris Business Solutions"
if(substr($1,1,2) == "o:"){next}
}1' file
Regards
What does 1 signifies here.
  #7 (permalink)  
Old 05-21-2008
benitdhotekar benitdhotekar is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
Solution

Hi,

You can build simple solution in perl for this.
Please let me know if you need source code for it.

Thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0