Sponsored Content
Top Forums Shell Programming and Scripting Match pattern and replace with string Post 302350729 by daPeach on Friday 4th of September 2009 06:03:01 PM
Old 09-04-2009
Code:
cat sol_nov.infile
  SELECT *
  FROM
    /*<new>*/abc_db./*<abc>*//*<hef>*/tbl_name
  
  WHERE
        (   new_dt >= cast(/*<from_date>*/'2007-08-01' as date)
        AND old_dt < cast(/*<to_date>*/'2007-08-02' as date)
         )
  ;
sed "s@\(/\*<new>\*/\)[^.]*\(\./\*<[^>]*>\*//\*<[^>]*>\*/\)@\1${new}\2\${abc}\${hef}_@
s@\(.*/\*<from_date>\*/'\)[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\([^)]*\)@\1\${from_dt}\2@
s@\(.*/\*<to_date>\*/'\)[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\([^)]*\)@\1\${to_date}\2@" sol_nov-20090904.infile
  SELECT *
  FROM
    /*<new>*/./*<abc>*//*<hef>*/${abc}${hef}_tbl_name
  
  WHERE
        (   new_dt >= cast(/*<from_date>*/'${from_dt}' as date)
        AND old_dt < cast(/*<to_date>*/'${to_date}' as date)
         )
  ;

You really should take time to read some docs about sed.
It'll take longer for me to explain (and I'll be less clear), than for you to check the 'sed, a stream editor' page about these 'simple' regexps.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace 1 word after pattern match

Hi, Here is my pattern CREATE USER LZ IDENTIFIED BY VALUES 'A0144280ESD70' DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP1 PROFILE DEVELOPER_D_1 ACCOUNT UNLOCK / The Sed command must look for the Line that contains TEMPORARY TABLESPACE and replace the immediate word... (4 Replies)
Discussion started by: rajan_san
4 Replies

2. Shell Programming and Scripting

Match pattern and replace

Hi All, I am new to unix shell scripting, I need your help guys in coming up with some thing for the following scenario: file1 ABC_BASE ${base} ABC_ACC ${acc} ABC_TEST ${test} 01-01-2006 ${from_dt} 01-15-2006 ${to_dt} file 2 I have an file2.sql file which contains: ####This... (4 Replies)
Discussion started by: sol_nov
4 Replies

3. Shell Programming and Scripting

replace pattern after the first pattern match

I need this. aaa OOOOO bbb ccc OOOOO ddd fff ggg OOOOO iii OOOOO I need all OOOOO replaced with PPPPP, but only change after the pattern ggg. So the first two OOOOO should not be changed. OUTPUT should be :- aaa (2 Replies)
Discussion started by: anilcliff
2 Replies

4. Shell Programming and Scripting

pattern match and replace another pattern in same line

I have a pattern username:x:32005:32006::/usr/local/user:/bin/bash I need to match the line containing username and replace /bin/bash with /usr/local/my/bin/noshell So it becomes username:x:32005:32006::/usr/local/user:/usr/local/my/bin/noshell (7 Replies)
Discussion started by: anilcliff
7 Replies

5. Shell Programming and Scripting

Match a Pattern & Replace The value Using AWK

I have a csv file in which i have to search a particular string and replace the data in any column with something else. How do i do it using awk. file ------ 2001,John,USA,MN,20101001,29091.50,M,Active,Y 2002,Mike,USA,NY,20090130,342.00,M,Pending,N... (3 Replies)
Discussion started by: Sheel
3 Replies

6. Shell Programming and Scripting

Help with Pattern match and replace

I have a file containing a multiple lines of the format sddfdsf_gaf/ywrtrtwrt_gaf ghfghfgh_ert/xcvxcvcv_ert werwerwwerw_adf/jkhjkhjkjhkjhk_adf I am interested in only the first 3 letters following the "_" character and make those 3 letters uppercase after extraction. So would like to convert... (5 Replies)
Discussion started by: inditopgun
5 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

How to replace with pattern match using Perl

I have to replace a line, if it has a pattern for example Suppose file.out contains: <tr><td class="cB">Hello</td><td class="cB">1245</td><td class="cB">958</td><td class="cRB">1.34</td><td class="cRB">1.36</td></tr> <tr><td class="cB">world</td><td class="cB">3256</td><td... (8 Replies)
Discussion started by: sol_nov
8 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. Shell Programming and Scripting

If pattern match, replace it with #

This command is not working for me. awk '{if ($1 == server) {$1 = #server} }' /etc/ntp.conf # grep server /etc/ntp.conf # Use public servers from the pool.ntp.org project. server 0.rhel.pool.ntp.org iburst server 1.rhel.pool.ntp.org iburst server 2.rhel.pool.ntp.org iburst server... (5 Replies)
Discussion started by: kenshinhimura
5 Replies
PG_UNESCAPE_BYTEA(3)													      PG_UNESCAPE_BYTEA(3)

pg_unescape_bytea - Unescape binary for bytea type

SYNOPSIS
string pg_unescape_bytea (string $data) DESCRIPTION
pg_unescape_bytea(3) unescapes PostgreSQL bytea data values. It returns the unescaped string, possibly containing binary data. Note When you SELECT a bytea type, PostgreSQL returns octal byte values prefixed with '' (e.g. 32). Users are supposed to convert back to binary format manually. This function requires PostgreSQL 7.2 or later. With PostgreSQL 7.2.0 and 7.2.1, bytea values must be cast when you enable multi- byte support. i.e. INSERT INTO test_table (image) VALUES ('$image_escaped'::bytea); PostgreSQL 7.2.2 or later does not need a cast. The exception is when the client and backend character encoding does not match, and there may be multi-byte stream error. User must then cast to bytea to avoid this error. PARAMETERS
o $data - A string containing PostgreSQL bytea data to be converted into a PHP binary string. RETURN VALUES
A string containing the unescaped data. EXAMPLES
Example #1 pg_unescape_bytea(3) example <?php // Connect to the database $dbconn = pg_connect('dbname=foo'); // Get the bytea data $res = pg_query("SELECT data FROM gallery WHERE name='Pine trees'"); $raw = pg_fetch_result($res, 'data'); // Convert to binary and send to the browser header('Content-type: image/jpeg'); echo pg_unescape_bytea($raw); ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.5.1 | | | | | | | A warning is thrown if the input string is | | | invalid. | | | | +--------+---------------------------------------------------+ SEE ALSO
pg_escape_bytea(3), pg_escape_string(3). PHP Documentation Group PG_UNESCAPE_BYTEA(3)
All times are GMT -4. The time now is 03:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy