LinuxQuestions.org
Review your favorite Linux distribution.
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-17-2013, 10:12 AM   #1
ravisingh1
Member
 
Registered: Apr 2013
Location: Mumbai
Distribution: Ubuntu13.10
Posts: 291

Rep: Reputation: Disabled
Add a text in the 1st line of a file using perl


Please assist me and show me how can i add a text on the 1st line of a file. i can get it done with sed but how to do with perl.
 
Old 07-17-2013, 10:22 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ravisingh1 View Post
Please assist me and show me how can i add a text on the 1st line of a file. i can get it done with sed but how to do with perl.
How about looking it up? Did you try that? Putting "how to add a line to the top of a file with perl" into Google will, amazingly, give you some answers. Reading the Perl documentation will too:
http://learn.perl.org/faq/perlfaq5.html

Look for the work "top" or "prepend" in that file. Since you provide no details or give any examples of what you've done/tried on your own, that will give you a start.
 
Old 07-17-2013, 10:24 AM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I know next to nothing about perl

http://perldoc.perl.org/perlfaq5.htm...ing-of-a-file?


Edit: web search "perl insert line"

Last edited by Firerat; 07-17-2013 at 10:26 AM.
 
Old 07-17-2013, 10:32 AM   #4
ravisingh1
Member
 
Registered: Apr 2013
Location: Mumbai
Distribution: Ubuntu13.10
Posts: 291

Original Poster
Rep: Reputation: Disabled
Thanks both of you a lot. The documentation seems great. I w'd go through it.
 
Old 07-17-2013, 12:53 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ravisingh1 View Post
Thanks both of you a lot. The documentation seems great. I w'd go through it.
The first thing you should do is try to look things up on your own, and post a question AFTER you've tried, but can't find an answer. Questions like this make it seem like you want others to look things up for you.
 
Old 07-18-2013, 07:40 AM   #6
ravisingh1
Member
 
Registered: Apr 2013
Location: Mumbai
Distribution: Ubuntu13.10
Posts: 291

Original Poster
Rep: Reputation: Disabled
You are right, TBOne. i should have 1st looked up in google/net.
BTW, thanks againg for the document as it helped me a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] How to add text to a file's first and last line without using vi infinite_scale Linux - Desktop 3 03-02-2012 08:10 AM
PHP: Find a string in a text file and add something to that line aocferreira Programming 1 05-26-2011 01:52 PM
Perl question: delete line from text file with duplicate match at beginning of line mrealty Programming 7 04-01-2009 06:46 PM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 05:08 PM
How to add a text to first line of a text file? oskeewow Linux - Newbie 6 04-23-2008 12:40 PM

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

All times are GMT -5. The time now is 09:27 PM.

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