Sponsored Content
Top Forums Shell Programming and Scripting Extract words before and after a pattern/regexp Post 302177454 by drl on Friday 21st of March 2008 07:38:30 AM
Old 03-21-2008
Hi.

Adjusting the RE in script file p1 to account for whitespace on either side of bingo, etc.:
Code:
#!/usr/bin/perl

use warnings;
use strict;

open( INFILE, "data1" ) || die " Can't open input file.\n";

while (<INFILE>) {
  if (s/.*(\w+)\s*bingo\s*(\w+).*/$1 $2/) {
    print;
  }

}

exit(0);

Producing:
Code:
% ./p1
a but

See man perlre for details ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with regexp for IP-Adress Pattern

Hi all Unix Gurus! Since hours (even days :-)) I'm trying to find the correct pattern to search for IP addesses in text files. The pattern to find a IP address itself is not too difficult: '((||1{2}|2|2{2})\.){3,}(||1{2}|2|2{2})' BUT, of course the above pattern is also matching lines like... (9 Replies)
Discussion started by: desertchannel
9 Replies

2. UNIX for Advanced & Expert Users

I am trying to find pattern between two words but unable to get that pattern..

HI.... It's fallow up file .. #./show.sh click enter button.. i am gettng the fallowup file. its keep on running every time why because there are lots of users working on it. In that file i want to search pattern between two words for ex: SELECT DISTINCT... (7 Replies)
Discussion started by: ksr.test
7 Replies

3. Shell Programming and Scripting

extract string until regexp from backside

Hi, I searched in the forums, but I didn't find a good solution. My problem is: I have a string like "TEST.ABC201005.MONTHLY.D101010203". I just want to have the string until the D100430, so that the string should look like: "TEST.ABC201005.MONTHLY.D" The last characters after the D can be... (8 Replies)
Discussion started by: elifchen
8 Replies

4. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

5. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

6. Shell Programming and Scripting

Perl regexp to extract first and second column

Hi, I am trying with the below Perl one-liner using regular expression to extract the first and second column of a text file: perl -p -e "s/\s*(\w+).*/$1/" perl -p -e "s/\s*.+\s(.+)\s*/$1\n/" whereas the text file's data looks like: Error: terminated 2233 Warning: reboot 3434 Warning:... (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Shell Programming and Scripting

Extract words starting with a pattern from a file

Hi Guys.. I have a file and i want to extract all words that starts with a pattern 'ABC_' or 'ADF_' For example, ABC.txt ---- INSERT INTO ABC_DLKFJAL_FJKLD SELECT DISTINCT S,B,C FROM ADF_DKF_KDFJ_IERU8 A, ABC_LKDJFREUE9_FJKDF B WHERE A.FI=B.EI; COMMIT; Output : ABS_DLKFJAL_FJKLD,... (5 Replies)
Discussion started by: Pramod_009
5 Replies

8. Shell Programming and Scripting

awk regexp to print repetitive pattern

How to use regexp to print out repetitive pattern in awk? $ awk '{print $0, "-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-"}' output: - - - - - - - - - - - -I tried following which does not give what I want, of course. awk '{print $0, "-\t{11}-"}' output: - ... (10 Replies)
Discussion started by: yifangt
10 Replies

9. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies

10. UNIX for Beginners Questions & Answers

TCL script to delete a pattern(regexp)

Hi I am writing a TCL script to delete a certain in a file My Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj; output dk; (1 Reply)
Discussion started by: kshitij
1 Replies
finddialog(1)							  [incr Widgets]						     finddialog(1)

__________________________________________________________________________________________________________________________________________________

NAME
finddialog - Create and manipulate a find dialog widget SYNOPSIS
finddialog pathName ?options? INHERITANCE
itk::Toplevel <- Shell <- Dialogshell <- Finddialog STANDARD OPTIONS
activeBackground activeForegroundbackgroundborderWidth cursor disabledForeground fontforeground highlightColor highlightThickness insertBackgroundinsertBorderWidth insertOffTime insertOnTime insertWidth selectBackground selectBorderWidth selectColor selectForeground See the "options" manual entry for details on the standard options. ASSOCIATED OPTIONS
selectColor See the "checkbutton" widget manual entry for details on the above associated options. selectColor See the "entryfield" widget manual entry for details on the above associated options. labelFont See the "labeledwidget" widget manual entry for details on the above associated options. INHERITED OPTIONS
buttonBoxPadX buttonBoxPadY buttonBoxPos padX padY separator thickness See the "dialogshell" widget manual entry for details on the above inherited options. height master modality width See the "shell" widget manual entry for details on the above inherited options. title See the "Toplevel" widget manual entry for details on the above inherited options. WIDGET-SPECIFIC OPTIONS Name: clearCommand Class: Command Command-Line Switch: -clearcommand Specifies a command to be invoked following a clear operation. The option is meant to be used as means of notification that the clear has taken place and allow other actions to take place such as disabling a find again menu. Name: matchCommand Class: Command Command-Line Switch: -matchcommand Specifies a command to be invoked following a find operation. The command is called with a match point as an argument which identi- fies where exactly where in the text or scrolledtext widget that the match is located. Should a match not be found the match point is {}. The option is meant to be used as a means of notification that the find operation has completed and allow other actions to take place such as disabling a find again menu option if the match point was {}. Name: patternBackground Class: Background Command-Line Switch: -patternbackground Specifies the background color of the text matching the search pattern. It may have any of the forms accepted by Tk_GetColor. The default is gray44. Name: patternForeground Class: Background Command-Line Switch: -patternforeground Specifies the foreground color of the text matching the search pattern. It may have any of the forms accepted by Tk_GetColor. The default is white. Name: searchBackground Class: Background Command-Line Switch: -searchbackground Specifies the background color of the line containing the matching the search pattern. It may have any of the forms accepted by Tk_GetColor. The default is gray77. Name: searchForeground Class: Background Command-Line Switch: -searchforeground Specifies the foreground color of the line containing the matching the search pattern. It may have any of the forms accepted by Tk_GetColor. The default is black. Name: textWidget Class: TextWidget Command-Line Switch: -textwidget Specifies the text or scrolledtext widget to be searched. __________________________________________________________________________________________________________________________________________________ DESCRIPTION
The finddialog command creates a find dialog that works in conjunction with a text or scrolledtext widget to provide a means of performing search operations. The user is prompted for a text pattern to be found in the text or scrolledtext widget. The search can be for all occurances, by regular expression, considerate of the case, or backwards. METHODS
The finddialog command creates a new Tcl command whose name is pathName. This command may be used to invoke various operations on the wid- get. It has the following general form: pathName option ?arg arg ...? Option and the args determine the exact behavior of the command. The following commands are possible for finddialog widgets: INHERITED METHODS
add buttonconfigure defaulthide invoke show See the "buttonbox" widget manual entry for details on the above inherited methods. activate center deactivate See the "shell" widget manual entry for details on the above inherited methods. WIDGET-SPECIFIC METHODS pathName cget option Returns the current value of the configuration option given by option. Option may have any of the values accepted by the finddialog command. pathName clear Clears the pattern in the entry field and the pattern matchin indicators in the text or scrolledtext widget. 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 finddialog command. pathName find Search for a specific text string in the text widget given by the -textwidget option. This method is the standard callback for the Find button. It is made available such that it can be bound to a find again action. COMPONENTS
Name: all Class: Checkbutton The all component specifies that all the matches of the pattern should be found when performing the search. See the "checkbutton" widget manual entry for details on the all component item. Name: backwards Class: Checkbutton The backwards component specifies that the search should continue in a backwards direction towards the beginning of the text or scrolledtext widget. See the "checkbutton" widget manual entry for details on the backwards component item. Name: case Class: Checkbutton The case component specifies that the case of the pattern should be taken into consideration when performing the search. See the "checkbutton" widget manual entry for details on the case component item. Name: pattern Class: Entryfield The pattern component provides the pattern entry field. See the "entryfield" widget manual entry for details on the pattern compo- nent item. Name: regexp Class: Checkbutton The regexp component specifies that the pattern is a regular expression. See the "checkbutton" widget manual entry for details on the regexp component item. EXAMPLE
scrolledtext .st pack .st .st insert end "Now is the time for all good men " .st insert end "to come to the aid of their country" finddialog .fd -textwidget .st .fd center .st .fd activate AUTHOR
Mark L. Ulferts KEYWORDS
finddialog, dialogshell, shell, widget Tk finddialog(1)
All times are GMT -4. The time now is 04:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy