[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

add a fixed text to the beginning of every line

I have a file like this:

yellow
brown
red

How do I add with Perl or PHP (command-line in Windows) - with the fastest execution time - the fixed text "100" to the beginning of every line, obtaining the following?

100yellow
100brown
100red
0
lucavilla
Asked:
lucavilla
  • 2
2 Solutions
 
ozoCommented:
perl -i.bak -pe "s/^/100" file
0
 
lucavillaAuthor Commented:
ozo, I get this error:

c:\Perl\bin\perl -i.bak -pe "s/^/100" input.txt
Substitution replacement not terminated at -e line 1.
0
 
Adam314Commented:
There is a missing / at the end.  It should be:
    c:\Perl\bin\perl -i.bak -pe "s/^/100/" input.txt
0
 
lucavillaAuthor Commented:
Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now