Sponsored Content
Top Forums UNIX for Dummies Questions & Answers searching words & print prefixed string after it Post 302645305 by birei on Wednesday 23rd of May 2012 08:12:05 AM
Old 05-23-2012
Hi A-V,

One way using perl:
Code:
$ cat infile
This is a book
The book is on the shelf and the pen is on the table
$ cat script.pl
use strict;
use warnings;

my %word = map { $_ => 1 } qw/the and a/;

while ( <> ) {
        chomp;
        my @f = split;
        for my $pos ( 0 .. $#f ) {
                if ( exists $word{ lc $f[ $pos ] } ) {
                        my $last_word = $pos + 5;
                        printf qq[%s %s\n], ucfirst $f[ $pos ], join qq[ ], @f[ $pos + 1 .. ($last_word > $#f ? $#f : $last_word) ]; 
                }
        }
}
$ perl script.pl infile
A book
The book is on the shelf
The shelf and the pen is
And the pen is on the
The pen is on the table
The table

This User Gave Thanks to birei For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

searching and displaying most commonly used words

Hi guys, i need to search the most commonly occuring words in a file and display their counts of about 30000 words and the words shud not be of typ specified in file 2 e. words like is,for,the,an,he,she etc... k. file1: ALICE was beginning to get very tired of sitting by... (2 Replies)
Discussion started by: arunsubbhian
2 Replies

2. Shell Programming and Scripting

Searching words in a file containing a pattern

Hi all, I would like to print words in a file seperated by whitespaces containing a specific pattern like "=" e.g. I have a file1 containing strings like %cat file1 The= some= in wish= born <eof> .I want to display only those words containing = i.e The= , some=,wish= ... (5 Replies)
Discussion started by: sree_123
5 Replies

3. Shell Programming and Scripting

searching for words between delimeters from the rear

Hi, i need to pick up dates and times from the file names which are of unequal length. The dates and time are delimited by dot. I am interested in getting the strings between the delimeter for fields -3, -4, -5 from behind (rear) so that the out put looks like : 071118.011300.556 I have... (2 Replies)
Discussion started by: oktbabs
2 Replies

4. Shell Programming and Scripting

Perl searching special words in lines

Hi , i am a new with perl, i want to made a script that find in file rows that start with specil words, as an example a line will start with" ............................................. specialword aaa=2 bbb=5 ............................................. and to put this in a new file... (3 Replies)
Discussion started by: alinalin
3 Replies

5. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

6. Shell Programming and Scripting

Searching for a string in .PDF files inside .RAR & .ZIP archives.

Hi, I have got a large number of .PDF files that are archived in .RAR & ZIP files in various directories and I would like to search for strings inside the PDF files. I would think you would need something that can recursively read directories, extract the .RAR/.ZIP file in memory, read the... (3 Replies)
Discussion started by: lewk
3 Replies

7. UNIX for Dummies Questions & Answers

Searching for multiple words on a line in any order issue

Hi again I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command: cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3 OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue Result: Tue Mar 25... (4 Replies)
Discussion started by: semaj
4 Replies

8. Shell Programming and Scripting

Awk: Searching for length of words between slash character

Dear UNIX Community, I have a set of file paths like the one below: \\folder name \ folder1 \ folder2 \ folder3 \ folder4 \\folder name \ very long folder name \ even longer name I would like to find the length of the characters (including space) between the \'s. However, I want... (6 Replies)
Discussion started by: vnayak
6 Replies

9. Shell Programming and Scripting

Finding my lost file by searching for words in it

Got a question for you guys...I am searching through a public directory (that has tons of files) trying to find a file that I was working on a longggggg time ago. I can't remember what it is called, but I do remember the content. It should contains words like this: Joe Pulvo botnet zeus... (5 Replies)
Discussion started by: statichazard
5 Replies

10. Shell Programming and Scripting

Print ALL matching words in a string

Hi. str=" {aaID=z_701; time=2012-10-08 00:00:00.000}; {aaID=S_300; time=2012-10-08 00:00:00.000}]}; ansokningsunderlag={anmaln......} {aaID=x_500; time=2012-10-08 00:00:00.000}]}; ansokningsunderlag={anmaln......}" I want to print: z_701 S_300 x_500 if I use : echo $str | sed -n... (4 Replies)
Discussion started by: freddan25
4 Replies
QwtSymbol(3)							 Qwt User's Guide						      QwtSymbol(3)

NAME
QwtSymbol - A class for drawing symbols. SYNOPSIS
#include <qwt_symbol.h> Public Types enum Style { NoSymbol = -1, Ellipse, Rect, Diamond, Triangle, DTriangle, UTriangle, LTriangle, RTriangle, Cross, XCross, HLine, VLine, Star1, Star2, Hexagon, StyleCnt } Public Member Functions const QBrush & brush () const virtual QwtSymbol * clone () const void draw (QPainter *p, const QPoint &pt) const void draw (QPainter *p, int x, int y) const virtual void draw (QPainter *p, const QRect &r) const bool operator!= (const QwtSymbol &) const virtual bool operator== (const QwtSymbol &) const const QPen & pen () const QwtSymbol (Style st, const QBrush &bd, const QPen &pn, const QSize &s) QwtSymbol () void setBrush (const QBrush &b) void setPen (const QPen &p) void setSize (int a, int b=-1) void setSize (const QSize &s) void setStyle (Style s) const QSize & size () const Style style () const virtual ~QwtSymbol () Detailed Description A class for drawing symbols. Member Enumeration Documentation enum QwtSymbol::Style Style See also: setStyle(), style() Constructor &; Destructor Documentation QwtSymbol::QwtSymbol () Default Constructor The symbol is constructed with gray interior, black outline with zero width, no size and style 'NoSymbol'. QwtSymbol::QwtSymbol (QwtSymbol::Stylestyle, const QBrush &brush, const QPen &pen, const QSize &size) Constructor. Parameters: style Symbol Style brush brush to fill the interior pen outline pen size size QwtSymbol::~QwtSymbol () [virtual] Destructor. Member Function Documentation const QBrush& QwtSymbol::brush () const [inline] Return Brush. QwtSymbol * QwtSymbol::clone () const [virtual] Allocate and return a symbol with the same attributes Returns: Cloned symbol void QwtSymbol::draw (QPainter *painter, const QRect &r) const [virtual] Draw the symbol into a bounding rectangle. This function assumes that the painter has been initialized with brush and pen before. This allows a much more performant implementation when painting many symbols with the same brush and pen like in curves. Parameters: painter Painter r Bounding rectangle void QwtSymbol::draw (QPainter *painter, const QPoint &pos) const Draw the symbol at a specified point. Parameters: painter Painter pos Center of the symbol void QwtSymbol::draw (QPainter *p, intx, inty) const Draw the symbol at a point (x,y). bool QwtSymbol::operator!= (const QwtSymbol &other) const != operator bool QwtSymbol::operator== (const QwtSymbol &other) const [virtual] == operator const QPen& QwtSymbol::pen () const [inline] Return Pen. void QwtSymbol::setBrush (const QBrush &brush) Assign a brush. The brush is used to draw the interior of the symbol. Parameters: brush Brush void QwtSymbol::setPen (const QPen &pen) Assign a pen The pen is used to draw the symbol's outline. The width of non cosmetic pens is scaled according to the resolution of the paint device. Parameters: pen Pen See also: pen(), setBrush(), QwtPainter::scaledPen() void QwtSymbol::setSize (const QSize &size) Set the symbol's size Parameters: size Size void QwtSymbol::setSize (intwidth, intheight = -1) Specify the symbol's size. If the 'h' parameter is left out or less than 0, and the 'w' parameter is greater than or equal to 0, the symbol size will be set to (w,w). Parameters: width Width height Height (defaults to -1) void QwtSymbol::setStyle (QwtSymbol::Styles) Specify the symbol style. The following styles are defined: NoSymbol No Style. The symbol cannot be drawn. Ellipse Ellipse or circle Rect Rectangle Diamond Diamond Triangle Triangle pointing upwards DTriangle Triangle pointing downwards UTriangle Triangle pointing upwards LTriangle Triangle pointing left RTriangle Triangle pointing right Cross Cross (+) XCross Diagonal cross (X) HLine Horizontal line VLine Vertical line Star1 X combined with + Star2 Six-pointed star Hexagon Hexagon Parameters: s style const QSize& QwtSymbol::size () const [inline] Return Size. Style QwtSymbol::style () const [inline] Return Style. Author Generated automatically by Doxygen for Qwt User's Guide from the source code. Version 5.2.2 Mon Aug 1 2011 QwtSymbol(3)
All times are GMT -4. The time now is 03:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy