Help with perl -pi command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with perl -pi command
# 1  
Old 02-09-2011
Help with perl -pi command

Greetings to all,
I am trying to write or use a perl line command in a shell script to replace the first 9 characters on each line in a file to zero, regardless of what the first 9 characters are. This is how far I have gotten:
Code:
perl -pi -e 's/........../ filename

Thanks in advance for the help

Last edited by Franklin52; 02-10-2011 at 04:15 AM.. Reason: Please use code tags
Harleyrci
# 2  
Old 02-10-2011
Code:
perl -i -pe 's/^.{9}/0/' input_file

# 3  
Old 02-10-2011
Thanks a bunch. It works with a small modification. I need to replace the first nine characters or numbers with nine zeros. So i changed /0/ to /000000000/ it worked, but is the best method meaning do i have to type in the nine zeros into the command?
Harleyrci
# 4  
Old 02-10-2011
Mostly I used 'variables' or 'hard code info' in the replace part. For your question I tried a new way.
Code:
perl -i -pe 's/^.{9}/0 x 9/e' input_file

e - evaluation.For more info, read the perl regex modifier
# 5  
Old 02-10-2011
Greetings,
Thank you very much. Sorry for the late response, i work night shift...back to the grind.
Harleyrci
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl command

Hi Alll i need something in perl that can check if a hard mount ( /tools ) if mounted and, if it is not print "not mount" i had this, but it will not work because it looks for a directory which will always exist regardless if the mount if there are not #!/usr/bin/perl my $DELAY = 300;... (1 Reply)
Discussion started by: ab52
1 Replies

2. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

3. Shell Programming and Scripting

Send "perl -e '...' " command through SSH, from a perl script

Hey guys I am trying to send a perl -e command to a number of systems using SSH. The command should retrieve some information for me. The problem is, the remote shell tries to interpolate my variables and doesn't get it should take the command literally and just execute it. Below the code.... (2 Replies)
Discussion started by: clrg
2 Replies

4. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies

5. Shell Programming and Scripting

need help with perl command.

Hi Guys, I wanted to create a insert statement from a file. The solution was given Durden_tyler and malcomex999. Malcomex gave the solution in awk which was not working as my OS is SunOS. The perl command was working but it is giving wrong insert statements for some of the records. This is... (8 Replies)
Discussion started by: mac4rfree
8 Replies

6. Shell Programming and Scripting

combine two perl lines into a single perl command

Hi Everyone, i have a string 00:44:40 so: $tmp=~ s/://gi; $tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e; the output is 2680. Any way to combine this two lines into a single line? Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

7. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

8. Shell Programming and Scripting

awk command with PERL

Hi All, My Input file looks like below: Input: 100,200,300 $fw=`head -1 test.csv | awk -F, '{print \$1}'`; $fw="'$fw" $fw="$fw'" print $fw Output:'100' I want the first field to be printed in single quotes ('') like above. I could get the ouptput but the problem is single... (6 Replies)
Discussion started by: kmkbuddy_1983
6 Replies

9. UNIX for Advanced & Expert Users

Split Command in Perl

Hi, I have to split a line of the form 1232423#asdf#124324#54534#dcfg#wert#rrftt#4567 into an array in perl. I am using @fields; @fields=split('#',$line); if($fields eq "1") But this is not working. By using the syntax, the statements in "if" are never executed. Please help.... (9 Replies)
Discussion started by: rochitsharma
9 Replies

10. UNIX for Dummies Questions & Answers

perl print command

Hi, I am running this command in perl print "this is a test message @1.00 pm\n" but the output i am getting as this is a test message .00 pm pls help, how to get the proper output (2 Replies)
Discussion started by: vasikaran
2 Replies
Login or Register to Ask a Question