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
aoe-mkshelf(8)						      System Manager's Manual						    aoe-mkshelf(8)

NAME
aoe-mkshelf - create special device files for one shelf address SYNOPSIS
aoe-mkshelf {device-dir} {shelf-address} env n_partitions=1 aoe-mkshelf {device-dir} {shelf-address} DESCRIPTION
The aoe-mkshelf command is not needed on systems that have udev installed and is incompatible with aoe drivers that have the aoe_dyndevs module parameter set to 1. Systems lacking udev and having an aoe driver that uses static minor device numbers can use aoe-mkshelf to create the block special files necessary to access the AoE devices with the given shelf address. All aoe drivers prior to aoe6-50 use static minor device numbers. Versions 50 and up use dynamic minor device numbers when the module parameter aoe_dyndevs=1 is set. If you are using static minor device numbers and your aoe driver supports only one partition per device (whole-disk partitions), then the device files must match, and you should use the n_partitions environment variable described below. Arguments device-dir This should be the name of the directory where the block device files will be created. shelf-address This is the AoE major address, or shelf address, for which to create device nodes. For example, specifying a shelf address of 1 means that the e1.* device nodes will be created in device-dir. ENVIRONMENT VARIABLES
If the n_partitions variable is set in the environment, it will override the default number of partitions per aoe disk, namely 16. EXAMPLE
In this example, the root user on a host named nai creates special files for using the aoe disks in shelf 7. Then he remembers that the driver doesn't have partition support, so the command is called again with n_partitions set to 1. nai:~# aoe-mkshelf /dev/etherd 7 nai:~# ls /dev/etherd/e7.* | wc -l 160 nai:~# rm /dev/etherd/e7.* nai:~# n_partitions=1 aoe-mkshelf /dev/etherd 7 nai:~# ls /dev/etherd/e7.* | wc -l 10 nai:~# SEE ALSO
aoe-discover(8), aoe-interfaces(8), aoe-mkdevs(8), aoe-stat(8), aoetools(8), udev(7). AUTHOR
Ed L. Cashin (ecashin@coraid.com) aoe-mkshelf(8)
All times are GMT -4. The time now is 01:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy