copy substr in existing string in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copy substr in existing string in Perl
# 1  
Old 12-30-2008
copy substr in existing string in Perl

Any clue to write something to a particular location in Perl?

Suppose

$line = ‘abc cde 1234”

How to write ( example string "test") on location 4 without parsing the whole line.

Output should be $line = ‘abctest 1234”

this is not search and replace. just to add substring into some existing string.

thanks
# 2  
Old 12-31-2008
Hi.

Welcome to the forum.

Look through perldoc -q string ... cheers, drl
# 3  
Old 12-31-2008
Hopefully I'm not doing your school work for you:

Code:
$line = 'abc cde 1234';
substr $line,3,4,'test';
print $line;

Look up the substr() function for details
# 4  
Old 12-31-2008
Thanks. I did it aleady
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl substr or similar help

I have a large string containing about 17,500 characters and I would like to obtain the value for token. token only appears in the entire string once and is towards the end of the string at the 17,200 area but that could change. Using perl can someone assist me with obtaining the value which in... (10 Replies)
Discussion started by: azdps
10 Replies

2. Shell Programming and Scripting

Chksum on two directories then copy if they are not identical or existing

How can I have an intelligent script that will copy from source to destination directory if the file doesnt exist there or the chksum is not match. SOURCE directory: for i in `ls` > do > echo $i > md5sum $i > echo "" > done asdasda 00039a616135792fb609d04cf27aed95 asdasda ... (5 Replies)
Discussion started by: kenshinhimura
5 Replies

3. Shell Programming and Scripting

Cut string substr

friends as I can cut the first three characters in a string example: 400_FACTURACION_CANJES_20151217.txt Result 400 (2 Replies)
Discussion started by: tricampeon81
2 Replies

4. Ubuntu

Copy existing Ubuntu to boot from USB

Hello all, I am looking for a way to copy the existing Ubuntu server 12.04 to a USB (with all the packages and such) and make it boot from the USB. I have seen other threads about copying the CD image to the USB, which is not exactly I am looking for. Before I start diving into anything I... (4 Replies)
Discussion started by: br1an
4 Replies

5. Shell Programming and Scripting

perl code to search existing files

Hi, I have a string like: read_lib {$lib/a.lib $lib/b.lib $lib/c.lib ..... } Now, I want to search existence of all these *.lib files in $lib directory. Please suggest- how to do it. Thanks -rkg (2 Replies)
Discussion started by: rkg
2 Replies

6. Shell Programming and Scripting

20090620231013 to date format i am using substr, any simple way in perl?

Hi Everyone, $tmp="20090620231013"; $tmp = substr($tmp,0,8)." ".substr($tmp,8,2).":".substr($tmp,10,2).":".substr($tmp,12,2); So my output is: 20090620 23:10:13. I only can think substr is easy, any perl can do this just one line very simple efficient one? :eek: Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

7. UNIX for Dummies Questions & Answers

substr function in perl

Hi friends, I have written a perl code and it works fine but I am not sure tommorow it works or not, please help me. problem : When diff is 1 then success other than its failure but tomorrow its 20090401 and the enddate is 20090331. thats why I write the code this type but it does not work and... (1 Reply)
Discussion started by: tukuna82
1 Replies

8. UNIX for Dummies Questions & Answers

substr in perl

Let's assume that I have a file with contents delimited by pipe: "The mouse|ran up|the|clock" "May|had a|little|lamb" How would I use 'substr' to get the 3rd field. For example, "the" from the first line, and "little" from the second line? # Loop over a file and read $LINE { ... (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

9. Shell Programming and Scripting

How to copy one folder to another with existing files

For example, /tmp/folder1 includes /tmp/folder1/a /tmp/folder1/b /tmp/folder2 includes /tmp/c Is there a command without removing files in /tmp/folder2 first to copy the /tmp/folder1 to /tmp/folder2? and the result should be /tmp/folder2 will include only /tmp/folder2/a... (2 Replies)
Discussion started by: lalelle
2 Replies

10. Shell Programming and Scripting

substr from a string in Shell script

Shell Scripting Gurus, I am having a hard time :confused: trying to figure out what I am doing wrong in my script. Below is the script snippet. It gives an error when it tries to execute the expression. a=`expr substr $stringZ 5 10` #!/bin/bash echo "Hello" stringZ="abcABC123ABCabc"... (3 Replies)
Discussion started by: yajaykumar
3 Replies
Login or Register to Ask a Question