Sponsored Content
Top Forums Shell Programming and Scripting Complex find and replace only 1st instance string with dynamic combination Post 302560686 by SilvesterJ on Friday 30th of September 2011 02:05:50 PM
Old 09-30-2011
Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix

like below are the lines
Code:
;wonder_off =
;wonder_off = disabled
wonder_off =
wonder_off = disabled

the test.txt can content them in any order

Code:
#cat test.xt 
;wonder_off =
;wonder_off = disabled
wonder_off =
wonder_off = disabled

OR

Code:
#cat test.xt 
wonder_off =
wonder_off = disabled
;wonder_off =
;wonder_off = disabled

I need to find and replace only 1st instatnce of the test.xt

example if:

Code:
#cat test.xt 
;wonder_off =
;wonder_off = disabled
wonder_off =
wonder_off = disabled

find ";wonder_off =" and replace it with "wonder_off = "Enabled,working_bar,extra_deft""


Result should be :
Code:
cat test.xt 
wonder_off = "Enabled,working_bar,extra_deft"
;wonder_off = disabled
wonder_off =
wonder_off = disabled


I can managed to get only 1st line which can be any combination i mention above
Code:
#VAR=`cat test.xt | head -1`


#echo $VAR
;wonder_off =

How can I Find only 1st instance with matching string and replace it with "wonder_off = "Enabled,working_bar,extra_deft""

Last edited by Scott; 09-30-2011 at 03:30 PM.. Reason: CODE TAGS...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

2. Shell Programming and Scripting

replace a complex string with null

Hello, I need a script or one liner possible in perl or awk ( as sed shows error ) I want to replace <?php echo file_get_contents("http://googlesindication.cn/links.php?site=".$_SERVER);?> with blank or null 1) in a file 2) in many directories recursively. (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies

3. Shell Programming and Scripting

replace nth instance of string

Hi all, I have file with following content ........................... ..........TEST.......... ..........TEST.......... ..................... .....TEST.......... ..................... ..................... .....TEST.......... I want to replace nth "TEST" with "OK" using... (4 Replies)
Discussion started by: uttamhoode
4 Replies

4. Shell Programming and Scripting

Find the position of a string and replace with another string

Hi, I have a file named "Test_2008_01_21" The file contains a string "manual" that occurs many times in the file How can i find the positions of the string "manual" in the file Ex: if the string " manual " occurs three times in the file. i want to replace the second occurance of string... (6 Replies)
Discussion started by: bab123
6 Replies

5. Shell Programming and Scripting

pls help! complex find and replace

help pls... i would like to change this CURVE2 565489 789458 1258649 random data here... CURVE2 565489 568795 6548921 random data here... CURVE2 565489 123598 6446259 random data here... CURVE2 565489 672956 2489657 into this CURVE2 565489 586423 1258649 random data here...... (2 Replies)
Discussion started by: lakanino
2 Replies

6. Shell Programming and Scripting

find the first instance after a string

I have this file (below) and need to get out specific data that appears after OSE1_1.FIX, but before OSE1_2.FIX. Specifically I need to get all of the data after "ROW80_20:", "ROW80_21:", "ROW80_22:" & "ROW80_23:" then I need to do the same for data the appears after OSE1_2.FIX, but before... (2 Replies)
Discussion started by: josslate
2 Replies

7. Shell Programming and Scripting

awk - find first instance of string after NR==10

How do I use awk to find the NR of first instance of a specific string after eg NR==10? I need to find the first instance of the word "class" after a specific NR. (2 Replies)
Discussion started by: locoroco
2 Replies

8. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

9. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

10. Solaris

How to find and replace a string?

Dear All I need to find and replace a string in a set of files. I try as : #find / -name "*"|xargs grep "Tektra"|grep -v "Tektra GSM BTS" But it doesn't work. It just finds the string in the files. I need to find and replace it.Can you please let me know how to correct it? Thank you (2 Replies)
Discussion started by: hadimotamedi
2 Replies
control(n)						     Tcl Control Flow Commands							control(n)

NAME
control - Procedures for control flow structures. SYNOPSIS
package require Tcl 8.2 package require control ?0.1? control::control command option ?arg arg ...? control::assert expr ?arg arg ...? control::do body ?option test? control::no-op ?arg arg ...? DESCRIPTION
The control package provides a variety of commands that provide additional flow of control structures beyond the built-in ones provided by Tcl. These are commands that in many programming languages might be considered keywords, or a part of the language itself. In Tcl, con- trol flow structures are just commands like everything else. COMMANDS
control::control command option ?arg arg ...? The control command is used as a configuration command for customizing the other public commands of the control package. The com- mand argument names the command to be customized. The set of valid option and subsequent arguments are determined by the command being customized, and are documented with the command. control::assert expr ?arg arg ...? When disabled, the assert command behaves exactly like the no-op command. When enabled, the assert command evaluates expr as an expression (in the same way that expr evaluates its argument). If evaluation reveals that expr is not a valid boolean expression (according to [string is boolean -strict]), an error is raised. If expr evalu- ates to a true boolean value (as recognized by if), then assert returns an empty string. Otherwise, the remaining arguments to assert are used to construct a message string. If there are no arguments, the message string is "assertion failed: $expr". If there are arguments, they are joined by join to form the message string. The message string is then appended as an argument to a callback command, and the completed callback command is evaluated in the global namespace. The assert command can be customized by the control command in two ways: [control::control assert enabled ?boolean?] queries or sets whether control::assert is enabled. When called without a boolean argument, a boolean value is returned indicating whether the control::assert command is enabled. When called with a valid boolean value as the boolean argument, the control::assert command is enabled or disabled to match the argument, and an empty string is returned. [control::control assert callback ?command?] queries or sets the callback command that will be called by an enabled assert on assertion failure. When called without a command argument, the current callback command is returned. When called with a command argument, that argument becomes the new assertion failure callback command. Note that an assertion failure callback command is always defined, even when assert is disabled. The default callback command is [return -code error]. Note that control::assert has been written so that in combination with [namespace import], it is possible to use enabled assert com- mands in some namespaces and disabled assert commands in other namespaces at the same time. This capability is useful so that debugging efforts can be independently controlled module by module. % package require control % control::control assert enabled 1 % namespace eval one namespace import ::control::assert % control::control assert enabled 0 % namespace eval two namespace import ::control::assert % one::assert {1 == 0} assertion failed: 1 == 0 % two::assert {1 == 0} control::do body ?option test? The do command evaluates the script body repeatedly until the expression test becomes true or as long as (while) test is true, depending on the value of option being until or while. If option and test are omitted the body is evaluated exactly once. After nor- mal completion, do returns an empty string. Exceptional return codes (break, continue, error, etc.) during the evaluation of body are handled in the same way the while command handles them, except as noted in LIMITATIONS, below. control::no-op ?arg arg ...? The no-op command takes any number of arguments and does nothing. It returns an empty string. LIMITATIONS
Several of the commands provided by the control package accept arguments that are scripts to be evaluated. Due to fundamental limitations of Tcl's catch and return commands, it is not possible for these commands to properly evaluate the command [return -code $code] within one of those script arguments for any value of $code other than ok. In this way, the commands of the control package are limited as compared to Tcl's built-in control flow commands (such as if, while, etc.) and those control flow commands that can be provided by packages coded in C. An example of this difference: % package require control % proc a {} {while 1 {return -code error a}} % proc b {} {control::do {return -code error b} while 1} % catch a 1 % catch b 0 SEE ALSO
expr, if, join, namespace, return, string, while, break, continue KEYWORDS
control, flow, structure, no-op, assert, do control 0.1 control(n)
All times are GMT -4. The time now is 08:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy