Sponsored Content
Top Forums Shell Programming and Scripting Replace a particular pattern in a file Post 302474491 by durden_tyler on Wednesday 24th of November 2010 11:12:51 AM
Old 11-24-2010
Or using Perl -

Code:
$
$ cat f42
abcd
$$xyz=123
$$zef=789
 
$$mno=123
$$pqr=456
$
$
$ typeset -x VAR="999"
$
$ # Perl one-liner to substitute the value
$ perl -lne 'if (/^(\$\$pqr=).*/){print $1,$ENV{"VAR"}} else {print}' f42
abcd
$$xyz=123
$$zef=789
 
$$mno=123
$$pqr=999
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find and replace a pattern in a file

Hi I am having 2 files file1.c and file2.c Now i want to find all the occurances of pattern "abc" in file1.c, file2.c and replace with pattern "def" using shell script without using sed and with using sed. Thanks in advance... raju (1 Reply)
Discussion started by: krishnamaraju
1 Replies

2. Shell Programming and Scripting

replace a column in a file if it matches certain pattern

Hi, I want to replace a column in a file if it matches certain pattern. Can you help me on this. Here is the file content. 000000 1111111 2222222 011111 0123445 1234556 023445 1111111 2343455 if second column contains 1111111 i need to replace it with 0000000 Can you... (6 Replies)
Discussion started by: Krrishv
6 Replies

3. Shell Programming and Scripting

grep a pattern and replace a value in it and write to the same file.

I have some complication with this, I have a file like below for DEV_1 till DEV_10. and the db values are set accordinly which are not unique. For example DEV1,DEV4,DEV6 can have the same target DB name. I waned to identify for DEV_2 and then replace the TARGET_DATABASE value with the new DB... (6 Replies)
Discussion started by: yesmani
6 Replies

4. Shell Programming and Scripting

how to find the pattern inside the file and replace it

hello everybody, I have a group of file eg- sample1 sample2 sample3 sample4 each file contain this :- cat sample1 SEQ_NUM,1,UPESI1 My requirement is to change the value-UPESI1 to UPE10 in file which contain this pattern -UPESI1. any help is appreciated. (2 Replies)
Discussion started by: abhigrkist
2 Replies

5. UNIX for Dummies Questions & Answers

search a pattern across all file and replace it to all files.

Hi All, HP-UX oradev3 B.11.11 U 9000/800 I have few files, which contain texts. Now I need to search a pattern across all files and replace to that pattern with new one. For example, I have following files they have, which contain something like abc@abc.com, now I need to search text acorss... (6 Replies)
Discussion started by: alok.behria
6 Replies

6. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

7. Shell Programming and Scripting

Read from one file-Replace a pattern in another with the current one

Hi Friends, I have a text file like this cat main.txt I like this website cat website > new_website grep website > hello_website cat replace.txt hello unix apple Now, for each line read in 2.txt, I want the pattern "website" in 1.txt to be replaced with it. Basically, I... (9 Replies)
Discussion started by: jacobs.smith
9 Replies

8. Shell Programming and Scripting

Pattern replace from a text file using sed

I have a sample text format as given below <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456" From="1626711840902323"... (3 Replies)
Discussion started by: my_Perl
3 Replies

9. Shell Programming and Scripting

Replace pattern from nth field from a file

$ cat /cygdrive/d/Final2.txt 1,A ,Completed, 07.03_23.01 ,Jun 30 20:00 2,BBB,Pending,, 3,CCCCC,Pending,, 4,DDDDD,Pending,, 5,E,Pending,, 6,FFFF,Pending,, 7,G,Pending,, In the above file 4th field is date which is in MM.DD_HH.MIN format and I need to convert it to as it is there in 5th... (1 Reply)
Discussion started by: Amit Joshi
1 Replies

10. Shell Programming and Scripting

Find and Replace Pattern in file

Ok, so how many times have you received this request? I have been looking through the forum for examples and I see the use of tr, awk and sed to perform similar functions but not sure how to use the tools in this scenario and could use a push in the right direction. GOAL: Search for line... (9 Replies)
Discussion started by: djzah
9 Replies
Regexp::Common::number(3)				User Contributed Perl Documentation				 Regexp::Common::number(3)

NAME
Regexp::Common::number -- provide regexes for numbers SYNOPSIS
use Regexp::Common qw /number/; while (<>) { /^$RE{num}{int}$/ and print "Integer "; /^$RE{num}{real}$/ and print "Real "; /^$RE{num}{real}{-base => 16}$/ and print "Hexadecimal real "; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{num}{int}{-base}{-sep}{-group}{-places} Returns a pattern that matches an integer. If "-base => B" is specified, the integer is in base B, with "2 <= B <= 36". For bases larger than 10, upper case letters are used. The default base is 10. If "-sep => P" is specified, the pattern P is required as a grouping marker within the number. If this option is not given, no grouping marker is used. If "-group => N" is specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If "-group => N,M" is specified, digits between grouping markers must be grouped in sequences of at least N digits, and at most M digits. This option is ignored unless the "-sep" option is used. If "-places => N" is specified, the integer recognized must be exactly N digits wide. If "-places => N,M" is specified, the integer must be at least N wide, and at most M characters. There is no default, which means that integers are unlimited in size. This option is ignored if the "-sep" option is used. For example: $RE{num}{int} # match 1234567 $RE{num}{int}{-sep=>','} # match 1,234,567 $RE{num}{int}{-sep=>',?'} # match 1234567 or 1,234,567 $RE{num}{int}{-sep=>'.'}{-group=>4} # match 1.2345.6789 Under "-keep" (see Regexp::Common): $1 captures the entire number $2 captures the optional sign of the number $3 captures the complete set of digits $RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon} Returns a pattern that matches a floating-point number. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. If "-expon=P" is specified, the pattern P is used as the exponential marker. The default value of P is "qr/[Ee]/". For example: $RE{num}{real} # matches 123.456 or -0.1234567 $RE{num}{real}{-places=>2} # matches 123.45 or -0.12 $RE{num}{real}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{real}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{real}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $7 captures the optional exponent marker $8 captures the entire exponent value $9 captures the optional sign of the exponent $10 captures the digits of the exponent $RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>10}{...} $RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>8}{...} $RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>2}{...} $RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>16}{...} $RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group} The same as $RE{num}{real}, except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. For example: $RE{num}{decimal} # matches 123.456 or -0.1234567 $RE{num}{decimal}{-places=>2} # matches 123.45 or -0.12 $RE{num}{decimal}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{decimal}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{decimal}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $RE{num}{square} Returns a pattern that matches a (decimal) square. Because Perl's arithmetic is lossy when using integers over about 53 bits, this pattern only recognizes numbers less than 9000000000000000, if one uses a Perl that is configured to use 64 bit integers. Otherwise, the limit is 2147483647. These restrictions were introduced in versions 2.116 and 2.117 of Regexp::Common. Regardless whether "-keep" was set, the matched number will be returned in $1. This pattern is available for version 5.008 and up. $RE{num}{roman} Returns a pattern that matches an integer written in Roman numbers. Case doesn't matter. Only the more modern style, that is, no more than three repetitions of a letter, is recognized. The largest number matched is MMMCMXCIX, or 3999. Larger numbers cannot be expressed using ASCII characters. A future version will be able to deal with the Unicode symbols to match larger Roman numbers. Under "-keep", the number will be captured in $1. SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Bound to be plenty. For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.16.2 2011-04-16 Regexp::Common::number(3)
All times are GMT -4. The time now is 02:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy