Sponsored Content
Top Forums Shell Programming and Scripting How to substitute brackets in the beginning of string in perl? Post 302345737 by vanitham on Thursday 20th of August 2009 05:42:58 AM
Old 08-20-2009
How to substitute brackets in the beginning of string in perl?

Hi,

I have a string like this user can specify different query sets that is why "or" is mentioned:

Code:
$string="[[:<:]](";

or

$string="[[:<:]]((";

or

$string="[[:<:]](((";

or

$string="[[:>:]](((((";


What i have to do is substitute these brackets in the beginning.

I tried like this:

Code:
if($string=~/\[\[:<:\]\]\(/)
{
  $string=~s/\[\[:<:\]\]\(/\(\[\[:<:\]\]/g;
}
elsif($string=~/[[:<:]]\(\(/)
{
   #same here
}
elsif($string=~/[[:<:]]\(\(\(/)
{
  #same here
}
elsif($string=~/[[:<:]]\(\(\(\(/)
{
  #same here
}
elsif($string=~/[[:<:]]\(\(\(\(\(/)
{
  #same here
}

If statement i can use but i will be not be sure how many brackets will be there to substitute in the beginning?

I have to avoid this if loop!!

The output should be like this.

Code:
$string="\([[:<:]]";

or

$string="\(\([[:<:]]";

or

$string="\(\(\([[:<:]]";

etc like this all these different string examples are based on the users query sets that is why i just mentioned or such that user can give either like first string ( [[:<:]]\( ) or like second string ( [[:<:]]\(\( ).

How can i put or substitute brackets in the beginning of the sting?

Any ideas???

Regards
Vanitha
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match keyword on string and substitute under vi

Hi guys, with sed when I need to make a substitution inside a line containing a specific keyword, I usually use: sed '/keyword/ s/cat/dog/g' This will substitute "cat" with "dog" on those lines containing "keyword". Now I want to use this inside vi, for several reason that I cannot... (2 Replies)
Discussion started by: lycaon
2 Replies

2. Shell Programming and Scripting

To substitute a string in a line to another string

Suppose, d=ABC*.BGH.LKJ Now I want to replace 'DEFGHIJ' instead of '*.B' and store the value in d. Any Idea? Can we use sed here? The outout should be like this: d=ABCDEFGHIJGH.LKJ Please help.. (4 Replies)
Discussion started by: Niroj
4 Replies

3. Shell Programming and Scripting

substitution of string in brackets

Hi friends! I have a tab delimited file with two columns : GB_45_DRB SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRD SP:475928(mgmdksi rikgkg)|SP:587959(roykgl tiic-tm)|SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to... (4 Replies)
Discussion started by: jacks
4 Replies

4. Shell Programming and Scripting

Deleting part of a string enclosed in brackets

I use otool on OS X to figure out the shared libraries that a binary uses. I run this command: otool -L /Applications/Vidnik\ 0.13.0/Vidnik.app/Contents/MacOS/Vidnik And it returns an output similar to this: /Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:... (10 Replies)
Discussion started by: pcwiz
10 Replies

5. UNIX for Advanced & Expert Users

grep string containing [] brackets

Hello, I am trying to grep string with square brackets. for example I want to grep the below string in log.txt file. This is a test thanks in advance. (2 Replies)
Discussion started by: sureshcisco
2 Replies

6. Shell Programming and Scripting

Substitute Perl Script

I am having trouble with a part of my substitute script I am using. I have it look through a file and find an exact match and then if it finds that match in the 1 file it should run the following 1 liner on 3 different files. perl -pi -e 's/$CurrentName\s/$NewName/g' foo.cfg; The issue that is... (8 Replies)
Discussion started by: Takau
8 Replies

7. Programming

Substitute string using location (preferably perl).

I have a string like. ATATATATTATTATATTATATTATT I want to substitute the characters to "C" by using these locations 3 7 10 18 15 20 desired Output: ATCCCCCTTACCCCCCCCCCTTATT any clue will be great help. :wall: thanks in advance. (2 Replies)
Discussion started by: admax
2 Replies

8. UNIX for Dummies Questions & Answers

Find and substitute a string

Hi, I started exploring unix recently. Now i have got a requirement like i have a input file where i am having some strings line by line (One string Might be single line or multiple lines). Now i need find these strings in another file and if its found i have to replace it with another string... (2 Replies)
Discussion started by: Sivajee
2 Replies

9. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

10. Shell Programming and Scripting

[sed]: Substitute a string with a multiline value

Dear all, I try to replace a string of characters in a file (MyFile.txt) by a multiline value of the variable "Myvar": $ cat MyFile.txt DESCRIPTION '@TargetTable SCHEMA' ( @InputFlowDef ); $ The content of Myvar: $ echo "$Myvar" col1 , col2 , col3 $ (4 Replies)
Discussion started by: dae
4 Replies
wsreg_query_set_version(3WSREG) 		    Product Install Registry Library Functions			   wsreg_query_set_version(3WSREG)

NAME
wsreg_query_set_version, wsreg_query_get_version - set or get the version of a query SYNOPSIS
cc [flag ...] file ... -lwsreg [library ...] #include <wsreg.h> int wsreg_query_set_version(Wsreg_query *query, const char *version); char *wsreg_query_get_version(const Wsreg_query *query); DESCRIPTION
The wsreg_query_set_version() function sets the version specified by version in the query specified by query. If a version has already been set in the specified query, the resources associated with the previously set version are released. The wsreg_query_get_version() function gets the version string from the query specified by query. The resulting string is not a copy and must not be released by the caller. RETURN VALUES
The wsreg_query_set_version() function returns a non-zero value if the version was set correctly; otherwise 0 is returned. The wsreg_query_get_version() function returns the version from the specified query. If no version has been set, NULLt is returned. The resulting version string is not a copy and must not be released by the caller. USAGE
The query identifies fields used to search for a specific component in the product install registry. By specifying the version, the compo- nent search is narrowed to all components in the product install registry that have the specified version. Other fields can be specified in the same query to further narrow the search. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
wsreg_get(3WSREG), wsreg_initialize(3WSREG), wsreg_query_create(3WSREG), attributes(5) SunOS 5.10 22 Sep 2000 wsreg_query_set_version(3WSREG)
All times are GMT -4. The time now is 08:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy