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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-20-2009
Registered User
 

Join Date: Nov 2008
Location: Pune, India
Posts: 28
Post Perl - Enter text in a file in a place.

Hi,
I have a simple question:

I need to enter some text in a text file at a certain place via perl.
I would first need to find that specific text in the file and then I would like to insert a line after that particular line.

Say I have this text file:

I am a great Perl Programmer

I would like to learn Perl





Now I would like to insert a line called: "My Name is Som" between the two lines.
So I would need a regex to search the line: "I am a great Perl Programmer" and then insert "My Name is Som" in the next line.
What should be the command in perl? I know this is a dumb question.
Can anyone help?
Thanks

Last edited by som.nitk; 03-20-2009 at 01:49 PM..
Sponsored Links
  #2 (permalink)  
Old 03-20-2009
Registered User
 

Join Date: Jan 2008
Posts: 729
You don't need a regexp you just need to find the first line using index() or "eq" then print the line you want to go after that line. When you post some code you have written to try and solve this requirement I will help you some more.

Two approaches are using the Tie::File module that comes with perl or perls inplace editor.
Sponsored Links
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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Best place on the net to get Perl tutorials ? Browser_ice Shell Programming and Scripting 1 08-10-2006 02:43 AM
Perl text file Sn33R Shell Programming and Scripting 5 10-31-2003 11:59 AM
Enter text and display on logo perleo Shell Programming and Scripting 1 06-26-2003 11:42 AM
Can i ask the question of perl in the place? ybz3721 Programming 2 04-17-2002 05:13 AM
Update text files in place (string substitution) ?? kornshellmaven UNIX for Dummies Questions & Answers 1 07-17-2001 12:11 AM



All times are GMT -4. The time now is 09:08 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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0