Calling Patterns of ".*" from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Calling Patterns of ".*" from a file
# 1  
Old 05-23-2012
Question Calling Patterns of ".*" from a file

I used to create a file to read my patterns and call them with grep but now I want to use different sort of patterns and it does not work with a list on a accept file
Code:
Grep –F  –f acceptfile.txt mainfile.txt > outputfile.txt

I have a data like this as they are in sequence of 5
The box of tissues out of
The book, the pen and the

I have a list of words (the, of, and) and I am looking for a pattern of
The.* the
The.* of
The.* and
.
.
.

note: I seem to have problem with of and off and coffee as well Smilie


Basically a loop to go through each of them one by one…
Not sure if that’s possible but even if not I am more than happy to predefine all my patterns in the file
But now that I put that patterns in the file and call them, the output file is empty
Can you tell me what am I doing wrong ?
Thank you in advance
A-V
# 2  
Old 05-23-2012
You have to escape metacharacters
Code:
 
file.*  
Becomes:
file.\*

or put each line inside single tics. Also grep -F means "do not use metcharacters (regexp)" so even if it gets read in correctly it won't work.
# 3  
Old 05-23-2012
if can write a single line which will work and that is

Code:
grep 'The.* of' main.txt > output.txt

and it shows 90% correctly
but I have so many Patterns that I was thinking to create a file for them I have 10 words so each of them when compared with others will mean I have 100 patterns.

ideally I want to delete the words which are around the pattern as well so I would life to have a list which will be

the ---- of
the -- of

but first need to find a way for my 100 patterns
# 4  
Old 05-23-2012
We need more information than 'my patterns', we need examples of what you consider to be a pattern and what you expect it to match in your data in order to help you. The things you show with the * may be valid patterns, I cannot tell.
# 5  
Old 05-23-2012
my data looks like

The box of tissues out of
The book, the pen and the

I have a list of words that need to make a pattern of them

Quote:
example of the words: the, of, and, a
example of the patterns: the.*the, the.*of, of.*of, of.*the
the output should look like

the box of
the box of tissues out of
of tissues out of
the book, the
the book, the pen and the
the pen and the

but because I have loads of patterns, I want to same those patterns in a file and call it

Last edited by A-V; 05-23-2012 at 01:11 PM..
# 6  
Old 05-23-2012
You can save it to a file:
Code:
the.*
the
the.*of 
of.*of 
of.*the

Depending on your version of grep - if it is a modern grep the above will work like this
Code:
grep -f pattern_file search_file

# 7  
Old 05-23-2012
Might it be easier to put your data through tr -s ' \t' ' ' first, so you never need to worry about multiple spaces?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Any way to "alias" file patterns for use in a command?

First, I apologize for my 'noobness' with Linux and the shell. I'm running Ubuntu with zsh as my shell. What I'd like to be able to do is clean up a messy Downloads folder by moving categories of files to different directories with something like: mv dir/$vids dest mv dir/$music dest mv... (5 Replies)
Discussion started by: Apollo33
5 Replies

5. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

6. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question