Sponsored Content
Top Forums Shell Programming and Scripting find and Replace String in Perl - Regexp Post 302959274 by cillmor on Friday 30th of October 2015 06:12:44 PM
Old 10-30-2015
find and Replace String in Perl - Regexp

Trying to find and replace one string with another string in a file

Code:
#!/usr/bin/perl

	$csd_table_path = "/file.ntab";
	$find_str = '--bundle_type=021';
	$repl_str = '--bundle_type=021 --target=/dev/disk1s2';
	if( system("/usr/bin/perl -p -i -e 's/$find_str/$repl_str/' $csd_table_path") != 0 ) {
		print "\n\n\nERROR: adding new target to <$csd_table_path>!\n\n\n";
		exit 1;
	}
	print "Msg: file modified \n";

exit 0;

however getting errors ...

Bareword found where operator expected at -e line 1, near "--target"
(Missing operator before target?)
Unknown regexp modifier "/v" at -e line 1, at end of line
syntax error at -e line 1, near "--target"
Execution of -e aborted due to compilation errors.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find the position of a string and replace with another string

Hi, I have a file named "Test_2008_01_21" The file contains a string "manual" that occurs many times in the file How can i find the positions of the string "manual" in the file Ex: if the string " manual " occurs three times in the file. i want to replace the second occurance of string... (6 Replies)
Discussion started by: bab123
6 Replies

2. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

3. Shell Programming and Scripting

How to replace string in perl?

Hi, I have string like this: $query="#1,apple"; $string=$query; I want to replace #1 with fruit. I tried like this: string=~s/#\d+/$query/ig; print "\n string: $string\n"; It is working only when there is single #1 or #2 but when i give like #1,#2,#3,apple the above code... (2 Replies)
Discussion started by: vanitham
2 Replies

4. Shell Programming and Scripting

How to find the count and replace the particular part of string in perl?

Hi, I am taking the current time using localtime function in perl. For example if the time is: #Using localtime $time = "12:3:10"; I have to replace the value 3 (03) i.e second position to be 03. The output should be: 12:03:10 But if the other string for example: $str:... (1 Reply)
Discussion started by: vanitham
1 Replies

5. Shell Programming and Scripting

replace awk with a perl one liner (REGEXP and FS)

hello, I want to replace awk with a perl one liner in unix. i use in awk REGEX and FS ( field separator) because awk syntaxes in different unix os versions have not the same behaviour. Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse i have a file named "file" and want... (5 Replies)
Discussion started by: bora99
5 Replies

6. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

7. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

8. Solaris

How to find and replace a string?

Dear All I need to find and replace a string in a set of files. I try as : #find / -name "*"|xargs grep "Tektra"|grep -v "Tektra GSM BTS" But it doesn't work. It just finds the string in the files. I need to find and replace it.Can you please let me know how to correct it? Thank you (2 Replies)
Discussion started by: hadimotamedi
2 Replies

9. Shell Programming and Scripting

How to use regexp to find an ipaddress from a query string?

I need help with a regexp to find out the ip address which can possibly be present in a URL. The URLs can be in any of the following form <domain>?a=12345&d=somestring1 <domain>?c=10.10.10.100&d=somestring1 <domain>?a=12345&b=somestring1&c=10.1.2.4d=somestring2... (3 Replies)
Discussion started by: ampak
3 Replies

10. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies
atomic_inc(3C)															    atomic_inc(3C)

NAME
atomic_inc, atomic_inc_8, atomic_inc_uchar, atomic_inc_16, atomic_inc_ushort, atomic_inc_32, atomic_inc_uint, atomic_inc_ulong, atomic_inc_64, atomic_inc_ptr, atomic_inc_8_nv, atomic_inc_uchar_nv, atomic_inc_16_nv, atomic_inc_ushort_nv, atomic_inc_32_nv, atomic_inc_uint_nv, atomic_inc_ulong_nv, atomic_inc_64_nv, atomic_inc_ptr_nv - atomic inrement operations SYNOPSIS
#include <atomic.h> void atomic_inc_8(volatile uint8_t *target); void atomic_inc_uchar(volatile uchar_t *target); void atomic_inc_16(volatile uint16_t *target); void atomic_inc_ushort(volatile ushort_t *target); void atomic_inc_32(volatile uint32_t *target); void atomic_inc_uint(volatile uint_t *target); void atomic_inc_ulong(volatile ulong_t *target); void atomic_inc_64(volatile uint64_t *target); void atomic_inc_ptr(volatile void *target); uint8_t atomic_inc_8_nv(volatile uint8_t *target); uchar_t atomic_inc_uchar_nv(volatile uchar_t *target); uint16_t atomic_inc_16_nv(volatile uint16_t *target); ushort_t atomic_inc_ushort_nv(volatile ushort_t *target); uint32_t atomic_inc_32_nv(volatile uint32_t *target); uint_t atomic_inc_uint_nv(volatile uint_t *target); ulong_t atomic_inc_ulong_nv(volatile ulong_t *target); uint64_t atomic_inc_64_nv(volatile uint64_t *target); void *atomic_inc_ptr_nv(volatile void *target); These functions enable the inrementing (by one) of the value stored in target to occur in an atomic manner. The *_nv() variants of these functions return the new value of target. No errors are defined. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ atomic_add(3C), atomic_and(3C), atomic_bits(3C), atomic_cas(3C), atomic_dec(3C), atomic_or(3C), atomic_swap(3C), membar_ops(3C), attributes(5), atomic_ops(9F) The *_nv() variants are substantially more expensive on some platforms than the versions that do not return values. Do not use them unless you need to know the new value atomically. 13 May 2005 atomic_inc(3C)
All times are GMT -4. The time now is 03:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy