Sponsored Content
Top Forums Shell Programming and Scripting awk/sed string search and replace Post 302528603 by jville on Tuesday 7th of June 2011 12:59:28 PM
Old 06-07-2011
awk/sed string search and replace

Need help with either sed or awk to acheive the following

Code:
file1
-----

In the amazon forest
The bats eat all the time...
mon tue wed they would eat berries

In the tropical forest
The bats eat all the time...
on wed bats eat nuts

In the rain forest
The bats eat all the time...
on mon tue wed bats eat nats

In the above file I would like to look for the words "tropical forest" and then look for the word "wed"
if it exists then
add a "#" in front of the line and add a new line with the text "on mon tue wed they would eat berries"

The result would look like this
Code:
In the amazon forest
The bats eat all the time...
mon tue wed they would eat berries

In the tropical forest
The bats eat all the time...
#on wed bats eat nuts
on mon tue wed they would eat berries

In the rain forest
The bats eat all the time...
on mon tue wed bats eat nats

Your input is much appreciated !
Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to replace all occurences of a search string using sed

All, Here is what I am searching for using sed. 1 00640000106798 I want to replace that with the following. 8 0064B0000106798 I can do this easy enough from the command line using sed but I need to put the search string in a file and then execute the sed command within a... (2 Replies)
Discussion started by: mjs3221
2 Replies

2. Shell Programming and Scripting

search and replace with restriction (awk, sed)

Hello, i have a file like that foo A new bar A new bar B new I need to replace 'new' with 'done', but only in lines containing 'bar' AND 'A'. output file should then become foo A new bar A done bar B new Sorry im not able to figure it out, not even shure if i should take sed.... (10 Replies)
Discussion started by: knoxo
10 Replies

3. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

4. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

5. 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

6. Shell Programming and Scripting

Search and replace is not working by sed or awk

Hi , I have one file and in this file i have one like TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;: i want to replace this line with the following line TEST1... (4 Replies)
Discussion started by: ashissau
4 Replies

7. Shell Programming and Scripting

Another sed/awk search=>replace question

Hello, Need a little bit of help. Basically I need to replace lines in a file which were calculated wrong as it would 12 hours to regenerate the data. I need to calculate values based on other files which I've managed to figure out with grep/cut but now am stuck on how to shove these new... (21 Replies)
Discussion started by: f77coder
21 Replies

8. Shell Programming and Scripting

sed - search and replace whole string which contains dot

Hello. I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3" And I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3" And I would not found in the result : "string1.new_string2.new_string3"... (3 Replies)
Discussion started by: jcdole
3 Replies

9. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

10. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies
TIX(3)							       Tix Built-In Commands							    TIX(3)

NAME
tixSelect - Create and manipulate tixSelect widgets SYNOPSIS
tixSelect pathName ?options? SUPER-CLASS The TixSelect class is derived from the TixLabelWidget class and inherits all the commands, options and subwidgets of its super-class. STANDARD OPTIONS
The Select widget supports all the standard options of a frame widget. See the options(n) manual entry for details on the standard options. WIDGET-SPECIFIC OPTIONS [-allowzero allowZero] A boolean value that specifies whether the selection can be empty. When set to false, at least one button subwidget must be selected at any time. Note: When the Select widget is first constructed, the default selection is always empty, even if -allowzero is set to false. [-button- type buttonType] The type of buttons to be used as subwidgets inside the Select widget. By default, the standard Tk button widget class is used. [-command command] Specifies the TCL command to be executed when the -value of the Select widget is changed. This command will be invoked with two arguments. The first is the name of the button subwidget that has toggled. The second is a boolean value indicating whether the button subwidget is selected. This command is executed only when the -disableCallback option is set to false. [-disablecall- back disableCallback] A boolean value indicating whether callbacks should be disabled. When set to true, the TCL command specified by the -command option is not executed when the -value of the Select widget changes. Name: orientation Class: Orientation Switch: -orientation Alias: -orient Specifies the orientation of the button subwidgets. Only the values horizontal and vertical are recognized. This is a static option and it can only be assigned during the creation of the widget. [-label label] Specifies the string to display as the label of this Select widget. [-labelside labelSide] Specifies where the label should be displayed relative to the Select widget. Valid options are: top, left, right, bottom, none or acrosstop. [-padx padX] Specifies the horizontal padding between two neighboring button sub- widgets. This is a static option and it can only be assigned during the creation of the widget. [-padx padY] Specifies the vertical padding between two neighboring button subwidgets. This is a static option and it can only be assigned during the creation of the widget. [-radio radio] A boolean value that specifies whether the Select widget should act as a radio-box. When set to true, at most one button subwidget can be selected at any time. This is a static option and it can only be assigned during the creation of the widget. [-selectedbg selectedBg] Specifies the background color of all the selected button subwidgets. [-state state] Speci- fies the state of all the buttons inside the Select widget. Only the values normal and disabled are recognized. When the state is set to disabled, all user actions on this Select widget are ignore. [-validatecmd validateCmd] Specifies a TCL command to be called when the -value of the Select widget is about to change. This command is called with one parameter -- the new -value entered by the user. This command is to validate this new value by returning a value it deems valid. [-value value] The value of a Select widget is a list of the names of the button subwidgets that have been selected by the user. When you assign the value of a Select widget using the "config -value" widget command, the TCL command specified by the -command option will be invoked if some button subwidgets are toggled. [-variable variable] Specifies the global variable in which the value of the Select widget should be stored. The value of a Select widget is stored as a list of the names of the button subwidgets that have been selected by the user. The value of the Select widget will be automatically updated when this variable is changed. SUBWIDGETS
Name: label Class: Label The label subwidget. In addition, all the button subwidgets created as a result of the add widget command can be accessed by the subwidget command. They are identified by the buttonName parameter to the add widget command. Here is an example: set s [tixSelect .s] pack $s $s add eat -text Eat $s add sleep -text Sleep $s subwidget eat config -fg green $s subwidget sleep config -fg red DESCRIPTION
The tixSelect command creates a new window (given by the pathName argument) and makes it into a Select widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the Select widget such as its cur- sor and relief. The Select widget is a container of button subwidgets. It can be used to provide radio-box or check-box style of selection options for the user. WIDGET COMMANDS
The tixSelect command creates a new Tcl command whose name is the same as the path name of the Select widget's window. This command may be used to invoke various operations on the widget. It has the following general form: pathName option ?arg arg ...? PathName is the name of the command, which is the same as the Select widget's path name. Option and the args determine the exact behavior of the command. The following commands are possible for Select widgets: pathName add buttonName ?option value ... ? Adds a new button subwidget with the name buttonName into the Select widget. Additional configuration options can be given to con- figure the new button subwidget. pathName cget option Returns the current value of the configuration option given by option. Option may have any of the values accepted by the tixSelect command. pathName configure ?option? ?value option value ...? Query or modify the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. Option may have any of the values accepted by the tixSelect command. pathName invoke buttonName Invokes the button subwidget with the name buttonName. pathName subwidget name ?args? When no options are given, returns the pathname of the subwidget of the specified name. When options are given, the widget command of the specified subwidget will be called with these options. BINDINGS
When the user presses the left mouse button over the a button subwidget, it will be toggled and the -value option of the tixSelect widget will be changed. EXAMPLE
The following example creates a radio-box style iconbar for the user to choose one value among eat, work or sleep. set s [tixSelect .s -radio true -allowzero false] $s add eat -bitmap [tix getbitmap eat] $s add work -bitmap [tix getbitmap work] $s add sleep -bitmap [tix getbitmap sleep] KEYWORDS
Tix(n), Container Widget Tix 4.0 TIX(3)
All times are GMT -4. The time now is 07:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy