Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Replace all occurrences of strings with parentheses Post 302479593 by ff1969ff1969 on Saturday 11th of December 2010 05:51:49 PM
Old 12-11-2010
Question Replace all occurrences of strings with parentheses

Hi,
I tried to adapt bartus's solution to my problem, without success. I want to replace all the occurences of this:
Quote:
globalFunc(something)
with:
Quote:
something.memberFunc()
, where something can contain an arbitrary number of balanced parens and brakets.
Any ideas ?
Best,

Last edited by Scott; 12-12-2010 at 05:01 AM.. Reason: New thread; added link to other thread
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parentheses in perl find/replace

I'm trying to use the following command to do a batch find and replace in all commonly named files through a file hierarchy find . -name 'file' |xargs perl -pi -e 's/find/replace/g' which works fine except for a substitution involving parenthesis. As a specific example I'm trying to sub... (3 Replies)
Discussion started by: Jeffish
3 Replies

2. Shell Programming and Scripting

Replace text in parentheses

Hi I would like to replace a comma in parentheses to a semicolon for example. Other commas outside () stay unchanged. How can I do this? aaaa,bbb,ccc,ddd(eee,fff,ggg),hhh,iii to aaaa,bbb,ccc,ddd(eee;fff;ggg),hhh,iii Thanks (5 Replies)
Discussion started by: lalelle
5 Replies

3. Shell Programming and Scripting

Extracting strings surrounded by parentheses and seperate by commas

Excuse the terrible title. I have a text file of 1..n lines, each one containing at least one string between parentheses. Within each string, there is one or more strings separated by commas. I need to extract each string, thus: input file: (THIS,THAT) (THE,OTHER) (THING) (OR,MAYBE)... (6 Replies)
Discussion started by: kpfeif
6 Replies

4. Shell Programming and Scripting

sed replace multiple occurrences on the same line, but not all

Hi there! I am really enjoying working with sed. I am trying to come up with a sed command to replace some occurrences (not all) in the same line, for instance: I have a command which the output will be: 200.300.400.5 0A 0B 0C 01 02 03 being that the last 6 strings are actually one... (7 Replies)
Discussion started by: ppucci
7 Replies

5. UNIX for Dummies Questions & Answers

Print number of occurrences of many different strings

People, I need your help with making a script which will 1. take as an input the number of lines, smth like this: ((RUBROBACTER_1_PE1288 (((SALINISPORA_1_PE1863 SALINISPORA_1_PE1828)100 ((NOCARDIOIDES_2_PE2419 PROPIONIBACTERIUM_1_PE1395)96 ((((((((CORYNEBACTERIUM_1_PE1119... (3 Replies)
Discussion started by: roussine
3 Replies

6. Shell Programming and Scripting

how many occurrences of different strings are there in each FILE.

Hello , I need some help to pull the data from different files, simultaneously for the string provided. I want to search below strings. PTN:3763427632478 IDB:3298734287438 PTN:8734983298738 From the files BELOW CODE_FILE_LOG1 CODE_FILE_LOG2 CODE_FILE_LOG3 CODE_FILE_LOG4 (3 Replies)
Discussion started by: baraghun
3 Replies

7. Shell Programming and Scripting

awk and gsub - how to replace only the first X occurrences

I have a text (text.txt) and I would like to replace only the first 2 occurrences of a word (but I might need to replace more): For example, if text is this: CAR sweet head hat red yellow CAR book brown tiger CAR cow CAR CAR milk I would like to replace the word "CAR" with word... (12 Replies)
Discussion started by: bingel
12 Replies

8. Shell Programming and Scripting

PERL : Sort substring occurrences in array of strings

Hi, My developer is on vacation and I am not sure if there is something which is easier for this. I have an array of strings. Each string in the array has "%" characters in it. I have to get the string(s) which have the least number of "%" in them. I know how I can get occurrences : ... (7 Replies)
Discussion started by: sinpeak
7 Replies

9. Shell Programming and Scripting

Sed command to replace with pattern except for text and closing parentheses

Can someone help me with a sed command: There will be multiple occurences in a file that look like this: MyFunction(12c34r5) and I need to replace that with just the 12c34r5 for every occurrence. The text between the parentheses will be different on each occurrence, so I can't search for that.... (4 Replies)
Discussion started by: missb
4 Replies

10. Shell Programming and Scripting

GREP between last occurrences of two strings

Hi I have the server.log file as: Server Stopped ABC DEF GHI JKL Server Started MNO PQR STU Server Stopped VWX YZ ABC Server Started Server Stopped 123 456 789 (9 Replies)
Discussion started by: ankur328
9 Replies
TOPS(1) 						      General Commands Manual							   TOPS(1)

NAME
tops - perform in-place substitutions on code. SYNOPSIS
tops [-help] [-verbose] [-nocontext] [-nofileinfo] [-semiverbose)] [-dont] (-scriptfile script_name) | (find "search_pattern" [where ("sym- bol"...) isOneOf {("match"...)...}] ...) | (replace "search_pattern" with "replacement_pattern" | same [where ("symbol"...) isOneOf {("match"...)...}]... [within ("symbol") {...}]... [error "message"] [warning "message"]) | ( replacemethod "selector" with "new_selector"{ [replace "symbol" with "symbol_replacement"]... } [where ("symbol"...) isOneOf {("match" ...)...}]... [within ("symbol") {...}]... [error "message"] [warning "message"] ) [-classfile classfile] [filename ...] DESCRIPTION
tops is a tool that performs in-place substitutions on source files according to a set of rules. Each tops rule describes a particular translation. For example, one tops rule might specify that occurrences of the token 'Application' should be converted to 'NSApplication'. In tops syntax, this rule will appear as: replace "Application" with "NSApplication" OPTIONS
-help Displays the tops syntax line. -verbose Prints out the source code lines that are being changed by the command. -nocontext Instead of printing the whole source code line that is being changed or searched for, shows only the portion of the line that has the change. -nofileinfo Does not print the file name and line number information in verbose messages. -semiverbose Shows how much of the file has been processed. -dont Shows what changes would be made to the source code without actually performing the changes. -scriptfile script_name Specifies the script file containing the rules that tops will apply to your code. The script file can contain three types of rules: find, replace, and replacemethod. It also can contain C-style comments, /* ... */. find "search_pattern" Locates all occurrences of search_pattern in the file. search_pattern can contain literal strings and tokens in angle brackets, as described below. where ("symbol"...) isOneOf {("match"...)...} When search_pattern contains tokens in angle brackets, further refines what the token specified by symbol should match. replace "search_pattern" with "replacement_pattern" | same Replaces all occurrences of search_pattern in the file with replacement_pattern. same replaces search_pattern with itself. You usu- ally use same when you want to print out an error or warning message instead of replacing the code. within ("symbol") {...} Specifies further conversions within one of the tokens specified in search_pattern. find, replace, and replacemethod rules can appear within the angle brackets. error "message" Generates an #error message located at search_pattern. warning "message" Generates a #warning message located at search_pattern. replacemethod "selector" with "new_selector" Replaces all invocations, declarations, implementations, and @selector expressions using the method selector with new_selector. -classfile classfile Specifies a file that describes the class hierarchy used by the files being processed. filename ... Specifies the source file(s) you want to convert. You can specify more than one filename, separated by spaces. The files are con- verted in place; no backups are created. If no file is specified, the tops commands are performed on standard input. The simplest search pattern is a literal string, such as "Application". Within the search pattern, you can define tokens that specify a particular syntax element rather than a literal string. The tokens have the form: <type label> where: type Specifies the type of syntax element the token can match with. label Is a unique label that you assign to the token. type can be one of the following: a Matches any sequence of tokens. b Matches any balanced sequence of tokens, that is, a sequence of tokens within parentheses or curly braces. e Matches any expression. This is the default. s Matches any string. t Matches any one token. w Matches white space, including comments. In a replacemethod rule, three subtokens are defined for each token you specify in the selector. For each token <foo> in the selector, replacemethod defines the following. The Examples section shows an example of using one of these. <foo_arg> Represents the tokens in the invocation of the method, that is, what is supplied for the foo argument. <foo_type> Represents the type for foo that appears in the declaration. <foo_param> Represents the parameter in the declaration. replacemethod also defines the following labels: <implementation> Represents the body of the method implementation (not including curly braces). <receiver> Represents the receiver of the message. <call> Represents the entire method invocation (including the square brackets). EXAMPLES
The following is a typical tops command invocation. The script file MyRules.tops contains the find, replace, and replacemethod rules that are performed on the files in MyProjectDir. The -semiverbose option means that name of the file being processed and the progress of the command will be printed to standard output. tops -semiverbose -scriptfile MyRules.tops MyProjectDir/*.[hm] The following is a typical rule that a tops script file would contain. The rule renames the method removeRowAt:andFree: to removeRow:andRelease: in all invocations, declarations, implementations, and @selector expressions. replacemethod "removeRowAt:andFree:" with "removeRow:andRelease:" The following rule marks all calls to the function NXGetNamedObject() with the error message. same means replace this function with itself. NXGetNamedObject() will still appear in the file, but it will be marked by the error message. <b args> specifies to replace all of the arguments in between the parentheses as well. replace "NXGetNamedObject(<b args>)" with same error "ApplicationConversion: NXGetNamedObject() is obsolete. Replace with nib file outlets." The following rule renames the method in all occurrences, and swaps the second and third argument in all invocations and declarations. replacemethod "browser:fillMatrix:<2>inColumn:<3>" with "browser:createRowsForColumn:<3>inMatrix:<2>" The following rule renames the method in all occurrences. In the invocations, it reverses the value specified for the flag argument. replacemethod "myMethod:<flag>" with "myNewMethod:<flag>" { replace "<flag_arg>" with "!<flag_arg>" } The following rule renames the method initContent:style:backing:buttonMask:defer: to initWithContentRect:styleMask:backing:defer: in all occurrences. In the declarations of this method, it changes the type for the style argument to be unsigned int and the type for the backing argument to be NSBackingStoreType. replacemethod "<old>" with "<new>" { replace "<style_type>" with "(unsigned int)" replace "<backing_type>" with "(NSBackingStoreType)" } where ("<old>", "<new>") isOneOf { ("initContent:style:<style> backing:<backing> buttonMask:<bmask> defer:<flag>", "initWithContentRect:styleMask:<style> backing:<backing> defer:<flag>"), } The following rule renames the method minFrameWidth:forStyle:buttonMask: to minFrameWidthWithTitle:styleMask: in all occurrences. Within invocations of this method, it changes the style argument to be the logical OR of the previous style argument and the previous button mask argument. Within method declarations, it changes the type for the style argument to be unsigned int. Within the implementation of this method, it changes all uses of the button mask argument to the style argument. replacemethod "minFrameWidth:forStyle:<style> buttonMask:<bmask>" with "minFrameWidthWithTitle:styleMask:<style>" { replace "<style_arg>" with "<style_arg>|<bmask_arg>" replace "<style_type>" with "(unsigned int)" } within ("<implementation") { replace "<bmask_param>" "<style_param>" } Apple Computer, Inc. March 14, 1995 TOPS(1)
All times are GMT -4. The time now is 06:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy