Sponsored Content
Top Forums UNIX for Advanced & Expert Users Search and replace a array values in perl Post 302799289 by arindam guha on Friday 26th of April 2013 07:41:25 AM
Old 04-26-2013
Search and replace a array values in perl

Hi,
i want to search and replace array values by using perl

Code:
perl -pi -e "s/${d[$i]}/${b[$j]}" *.xml

i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.".
please tell me what's wrong this line
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

2. Shell Programming and Scripting

perl: Assigning array values..

I have to add a variable value to an array, something like this: ...... @my_array_name = $value_of_this_variable; This doesnt seem to work, any ideas why? Thanks! (4 Replies)
Discussion started by: looza
4 Replies

3. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

4. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

5. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

6. Shell Programming and Scripting

Greping array values in Bash like Perl

Hi, Is there an easy way to simulate following Perl code in Bash. if ( grep {$my_value eq $_} @ARGV ){ print "Do Something\n"; } else { die "Invalid value"; } (0 Replies)
Discussion started by: paragkalra
0 Replies

7. Shell Programming and Scripting

How to map the values of an array in perl?

Hi, I have 2 arrays: @names=qw(amith veena chaitra); @files=qw(file.txt file1.txt file3.txt); There is one to one relationship between names and files. There needs to be mapping created between names and files. The output should be like this: amith --> file.txt veena --->... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

Help search and replace hex values only in specific files

perl -pi -e 's/\x00/\x0d\x0a/g' `grep -l $'GS' filelist` This isn't working :confused:, it's not pulling the files that contain the regex. Please help me rewrite this :wall:. Ideally for this to work on 9K of 20K files in the directory, I've tried this but I don't know enough about awk... (7 Replies)
Discussion started by: verge
7 Replies

9. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

10. Shell Programming and Scripting

Perl next if @array (exclude a list of values)

I'm trying to exlude a list of values with perl to process while reading in a file. Is there a way to use the next if with a list? Example: @array = qw(val1 val2 val3 val6); while (<>) { next if $_ =~ @array; # values I don't want to process here print; # process the rest here }... (8 Replies)
Discussion started by: timj123
8 Replies
STR_IREPLACE(3) 							 1							   STR_IREPLACE(3)

str_ireplace - Case-insensitive version ofstr_replace(3).

SYNOPSIS
mixed str_ireplace (mixed $search, mixed $replace, mixed $subject, [int &$count]) DESCRIPTION
This function returns a string or an array with all occurrences of $search in $subject (ignoring case) replaced with the given $replace value. If you don't need fancy replacing rules, you should generally use this function instead of preg_replace(3) with the i modifier. PARAMETERS
If $search and $replace are arrays, then str_ireplace(3) takes a value from each array and uses them to search and replace on $subject. If $replace has fewer values than $search, then an empty string is used for the rest of replacement values. If $search is an array and $replace is a string, then this replacement string is used for every value of $search. The converse would not make sense, though. If $search or $replace are arrays, their elements are processed first to last. o $search - The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles. o $replace - The replacement value that replaces found $search values. An array may be used to designate multiple replacements. o $subject - The string or array being searched and replaced on, otherwise known as the haystack. If $subject is an array, then the search and replace is performed with every entry of $subject, and the return value is an array as well. o $count - If passed, this will be set to the number of replacements performed. RETURN VALUES
Returns a string or an array of replacements. EXAMPLES
Example #1 str_ireplace(3) example <?php $bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>"); ?> NOTES
Note This function is binary-safe. Caution Replacement order gotcha Because str_ireplace(3) replaces left to right, it might replace a previously inserted value when doing multiple replacements. Example #2 in the str_replace(3) documentation demonstrates how this may affect you in practice. SEE ALSO
str_replace(3), preg_replace(3), strtr(3). PHP Documentation Group STR_IREPLACE(3)
All times are GMT -4. The time now is 11:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy