Sponsored Content
Top Forums Shell Programming and Scripting Perl:string substitution Pattern: ='abc...', Post 302279167 by Niroj on Thursday 22nd of January 2009 04:21:47 AM
Old 01-22-2009
Quote:
Originally Posted by unknown123
then little change, try this:

try this:

my $str = " c1 ='mmdnn, , sdm = 'sm' ,m ,jkjk' , c2 = 'chj= kjk'' , khj ', c3='hhshhj, hsjh' ";

print "Before substitution-> $str\n";

$str =~ s/('[ ]*),([ ]*c)/$1:$2/g;

print "After substitution-> $str\n"; # Getting Wrong o/p
oh....! U took the advantage of 'c' here which is just an example..
ok let u give the real example whr i m facing the problem:


$sql=" UPDATE tab_nm SET string_nm =' 12th dec, 1984, 'op=1 ' ,s: 'g' ', name= ' Brian Hogg' , class = '1st, A.C: Field Pt. 0.1 ' WHERE HGR=24 ";

Actually I got the col_strings i.e:

$col_strings="string_nm =' 12th dec, 1984, 'op=1 ' , s: 'g' ', name= ' Brian Hogg' , class = '1st, A.C: Field Pt. 0.1 ' ";

Now I wanna substitute the $col_strings as:

string_nm =' 12th dec, 1984, 'op=1 ' , s: 'g' '| name= ' Brian Hogg' | class = '1st, A.C: Field Pt. 0.1 '

That means I need the column informations in the string. And this string is as general as an sql strings containg columns like

$sql=" UPDATE tab_nm SET string_nm =' 12th dec, 1984, 'op=1 ' ,s: 'g' ', name= ' Brian Hogg' , class = '1st, A.C: Field Pt. 0.1 ' WHERE HGR=24 ";



Plz think for a very generalized way.. not specific like 'c'...

Plz help me to separate the columns & their values by substituting the commas with '|' which devides the columns information

Last edited by Niroj; 01-22-2009 at 05:28 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pattern match and substitution, can you help?

pattern match and substitution, can you help? file named test.txt I want to replace all the words Event with the word Fatal in all lines containing the word ERR - but I also want to keep the output of the other lines not matching ERR Test.txt: Event 13 INF egegegege Event 14 INF... (4 Replies)
Discussion started by: frustrated1
4 Replies

2. Shell Programming and Scripting

how to make ABC into "ABC" ina file

suppose u have a file ABC CDF ADF FDG HAA AHH AHA so output shud be like "ABC" "CDF" "ADF" FDG " "HAA" "AHH" "AHA" (8 Replies)
Discussion started by: cdfd123
8 Replies

3. Shell Programming and Scripting

String start with ABC

Hi, How to find out the words starting with ABC in a file (K shell) I dont want the word having ABC in middle of any string. Thanks Subrat (1 Reply)
Discussion started by: subrat
1 Replies

4. Shell Programming and Scripting

string substitution in perl

Hi, I have a template file and want to replace 3 parameters to the values that I want. these values are in a parameter file. Any idea how to do this in perl? the parameter file looks like: host_name = jupiter PORT = 1562 IPADDRESS = 10.1.34.10 the template file has lots of entry.... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

5. Shell Programming and Scripting

What is difference between ./abc.sh and . abc.sh

Hi Friends I have one shell script abc.sh If I run it ./abc.sh and . abc.sh , then what is the difference.. Thanks Joy:confused: (1 Reply)
Discussion started by: itsjoy2u
1 Replies

6. Shell Programming and Scripting

pattern match url in string / PERL

Am trying to remove urls from text strings in PERL. I have the following but it does not seem to work: $remarks =~ s/www\.\s+\.com//gi; In English, I want to look for www. then I want to delete the www. and everything after it until I hit a space (but not including the space). It's not... (2 Replies)
Discussion started by: mrealty
2 Replies

7. Shell Programming and Scripting

How can I use if statement to check a string start with "abc"

I am trying to write a if statement in KSH that if a string is start with abc then print something, I have written some code as below but it doesn't work. Could someone please help me if ] then print success fi (5 Replies)
Discussion started by: yhever
5 Replies

8. Shell Programming and Scripting

get value between <abc and > by perl, awk

Hi Everyone, cat 1.txt a <abc b vfff c 000> d 4444 the output is: <abcvfff000> by using perl or awk, can get the value betwee "<abc" and ">", assume 1.txt has lots of those tags, so the output can filter out all those values. Please advice. Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

9. Shell Programming and Scripting

PERL : pattern matching a string stored in a variable

I have two variables, my $filename = "abc_yyyy_mm_dd.txt"; my $filename1 = " abc_2011_11_07.txt"; I need to perform some operations after checking if $filename has $filename1 in it i have used the below code, if($filename =~ /^$filename1/) { ---- -- } (2 Replies)
Discussion started by: irudayaraj
2 Replies

10. UNIX for Dummies Questions & Answers

Substitution mid pattern?

Hi there, I have a file that goes like this: b_cdbc_db_cd_bcd_aaa-bcd_cd That type of format, for many lines. What I want to do is enter a new line character for after the _ I write an expression to find "_...-" fine, but I don't know how to substitute this to be: "_\naaa-" - where... (1 Reply)
Discussion started by: maximus73
1 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy