473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to modify a file using perl script

1. I have a folder containing several files;
2. Now these files should be added a header with the file name in the first line;

How can I complish this using perl script?
Sep 14 '07 #1
5 4990
numberwhun
3,509 Expert Mod 2GB
1. I have a folder containing several files;
2. Now these files should be added a header with the file name in the first line;

How can I complish this using perl script?
First, welcome to TSDN.

Second, we would love to help assist you with any code you have written. What have you tried so? Can you post your code please?

Regards,

Jeff
Sep 14 '07 #2
KevinADC
4,059 Expert 2GB
This question is coverd in the perl FAQS:

perldoc: perlfaq5 files and formats
Sep 14 '07 #3
You can use UNIX command in perl, if u r working in unix platform.

and unix command is

sed -n "1i/
>ur line input
filename > $$


then

mv $$ filename
Sep 15 '07 #4
numberwhun
3,509 Expert Mod 2GB
You can use UNIX command in perl, if u r working in unix platform.

and unix command is

sed -n "1i/
>ur line input
filename > $$


then

mv $$ filename
Yes, you certainly can, but the thing to remember is that the system command(s) need to be inside of either back tics or the system() function.

Regards,

Jeff
Sep 15 '07 #5
KevinADC
4,059 Expert 2GB
use perls inplace editor:

Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. chdir('path/to/folder') or die "$!";
  3. @ARGV = <*.*>;
  4. $^I = '.bak';
  5. while(<>){
  6.    if ($. == 1) {
  7.       print "$ARGV\n";
  8.    }
  9.    print;
  10. }
change <*.*> to whatever is appropriate or leave as-is to edit all files in the folder.
Sep 16 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Sherman Willden | last post by:
I am trying to use Perl's XML::Twig to modify a version number in an XML document. At the very end of this posting is an excerpt from the xml document. Just before the xml excerpt is the Perl code...
2
by: Veeven | last post by:
Hi, Suppose I have an XML file like this on the web, say, http://www.example.com/list.xml <?xml version='1.0'?> <list> <item id='itm01'> <name>Item 1</name> <desc>This is item 1</desc>
1
by: von | last post by:
I am trying to write a single piece of data (that is generated from a Javascript) to a text file on my server via a Perl script. The Javascript is setup so that I can display the required data on...
12
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
1
by: TimEl | last post by:
Hi. Using Perl, I want to modify data in an XML file and print out the entire modified file, not just the elements I modify. In CPAN I have found that XPath allows me to pinpoint the elements...
1
by: raghav82 | last post by:
New to perl. c++ file which needs to invoke perl file and provide input for it.how to invoke it.i also want to know setting of environment variable in windows environment using the perl script. i set...
23
by: smarsh | last post by:
Hi, Someone put together a small perl script for me that uses day and time to determine which of two images to display (open.gif or closed.gif). I need to modify the script to also include a...
1
by: georgewa | last post by:
Greetings all, great forum, this is my first post. Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.