perl script to add a line into a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to add a line into a file
# 1  
Old 06-02-2008
perl script to add a line into a file

hi all

need a perl script to add a line into a file

thanks with anticipation
# 2  
Old 06-02-2008
You have to tell us more than that...

Otherwise...

perl -e 'print "this is a line to add to a file"' >> filename

would append a line just as

echo "this is a line" >> filename would do the same!
# 3  
Old 06-03-2008
Or in Perl

Code:
open (F, ">>file") || die "Could not open file: $!\n";
print F "another line\n";
close F;

This is more a function of the "append mode" of the operating system's open function than of Perl, but perhaps this is what you were looking for.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add a line in every file with perl commandline?

Hi, i want to add a line at the beginning of every file in a directory. perl -i.bkp -p -e 'print "#include /verif/pdd1/exu/sxs/6sTest/reset/dfu/top_level.reset\n" if $. == 1' *.reset But this command is updating only the first file in the directory. I think this is because $. is not resetting... (3 Replies)
Discussion started by: twistedpair
3 Replies

2. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

3. Shell Programming and Scripting

How to add a line in a file using perl script?

Hi all, I want to search for a line in a file using perl script and add a line above that line.Can any one suggest me command or code to that using script. Thanks BHarath (5 Replies)
Discussion started by: bharathece
5 Replies

4. UNIX for Dummies Questions & Answers

Replace line via perl script of file

Hi All, I wanted to do following. 1) If file exit then open file for reading and check if my string is there then i wanted to replace the entire line with that string + something else then close the file. 2) If file does not exit then i need to open the file and write to it. I am done with... (0 Replies)
Discussion started by: Tarun24
0 Replies

5. Shell Programming and Scripting

Need awk script to add a prefix to each line in file

Hello , I have file with below content : '165567885', '165568443', '165568805', I need an awk script that would add a prefix zero after first ' . Like '0165567885', '0165568443', '0165568805', Please help. Thanks in advance. (5 Replies)
Discussion started by: rmv
5 Replies

6. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

7. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

8. Shell Programming and Scripting

Reading each line of a file in perl script

HI I need to read each line (test.txt) and store it in a array (@test) How to do it in perl. Suppose i have a file test.txt. I have to read each line of the test.txt file and store it in a array @test. How to do it in perl. Regards Harikrishna (3 Replies)
Discussion started by: Harikrishna
3 Replies

9. Shell Programming and Scripting

script to add first line from another file in aix

Hi All, I want to add a header from one file to another file which is around 2GB in size currently i am using cat to do it. It took more time to process. Is there any way to do it? Please help me .. Thanks in Advance Selva S (4 Replies)
Discussion started by: selvarhce
4 Replies

10. Shell Programming and Scripting

add to first line of file using perl

Hey guys, I have a text file full of data and all I want to do with the thing is add the file extension name to the first line of the file. Here is what I have so far. I can't remember how to append to the first line of the file without deleting the exsisting data. #!/usr/local/bin/perl ... (5 Replies)
Discussion started by: kingdbag
5 Replies
Login or Register to Ask a Question