Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word Post 302616229 by chicchan on Friday 30th of March 2012 04:23:20 PM
Old 03-30-2012
Bug Thank you !!!

First of all, thank you all for your answers.Smilie

My OS is ubuntu 11.10.

I have a friend that is trying the same thing. In his computer the same command line works fine.

My control file does not have the ^ and $. Maybe I should add those to each line. My control looks like this (but much longer):

NGO2105
NGO1081
NGO2156
NGO2158


And I'm trying to look for those identification numbers in files that look like this (but longer):

B0C5G9_ACAM1 B0C5G9 158335687 AMAR329726:AM1_2537-MONOMER null null null 5681349 CP000828_GR null HBG284974 IPR009915 amr:AM1_2537 null HPLMLGF null null null null null PF07298 null CLSK872158 null null YP_001516859.1 null null null null CP000828:ABW27545.1 AM1_2537


So, sometimes I find things like NGO1081.1 and that is an incorrect value for me.

I have other type of files in which I'm searching for the identification numbers, but I think if it works with one it works with others.

Anyway, I found the problem doing some 'hello world'-like tests. Where my control file was like:

NGO2105
NGO1081


And the file I was searching in was like:

dghsahgjgdsNGO2105
NGO2105ghdshf
NGO2105
asghdfNGO2105dsfjh
(NGO2105)
NGO1081
NGO21


Then the output file was like:

dghsahgjgdsNGO2105
NGO2105ghdshf
NGO2105
asghdfNGO2105dsfjh
(NGO2105)


I was doing other tests right know, following several of your advises. And turned out that grep is doing it fine. I took some precautions like deleting hidden files (that were making some noise). The last command line that I used and work fine was:

Code:
fgrep -wf Id -h searchFiles/* >> outputFile

I don't know if the -f was necessary but it works fine with it.

Thank you for all your replies.Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

2. Shell Programming and Scripting

find a word in a file, and change a word beneath it ??

Hi all, I have a file with lines written somewhat like this. aaaa ccc aa linux browse = no xssxw cdcedc dcsdcd csdw police dwed dwd browse = no cdecec (2 Replies)
Discussion started by: vikas027
2 Replies

3. Shell Programming and Scripting

Find Exact word in file

Hi ALL, I want to search one string “20 “ i.e 20 with space. But my file where I am searching this “20 “ contain some data like 120 before image file truncated 220 Reports section succeeded 20 Transaction database .prd stopped 220 Reports section completed. When I search for the... (5 Replies)
Discussion started by: Jeevan Salunke
5 Replies

4. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

5. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

6. Shell Programming and Scripting

Compare two files word by word

I need to compare two files word by word using unix shell scripting. Could someone help me? I need the code which will compare the 1st word from file1 with 1st word from file2, 2nd word from file1 with 2nd word from file2 etc..., for all the lines. Example: File1: aaa bbb ccc ... (7 Replies)
Discussion started by: rsmohankumar
7 Replies

7. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

8. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

9. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

10. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies
british-english(5)						   Users' Manual						british-english(5)

NAME
british-english - a list of English words DESCRIPTION
/usr/share/dict/british-english is an ASCII file which contains an alphabetic list of words, one per line. FILES
There may be any number of word lists in /usr/share/dict/. /etc/dictionaries-common/words is a symbolic link to the currently-chosen /usr/share/dict/<language> file. /usr/share/dict/words is a symbolic link to /etc/dictionaries-common/words, and is the name by which other software should refer to the system word list. See select-default-wordlist(8) for more information, and/or to change the currently- chosen word list. The directory /usr/share/dict can contain word lists for many languages, with name of the language in English, e.g., /usr/share/dict/french and /usr/share/dict/danish contain respectively lists of French and Danish words if they exist. Such lists should be coded using the ISO 8859-1 character set encoding. SEE ALSO
ispell(1), select-default-wordlist(8), and the Filesystem Hierarchy Standard. HISTORY
The words lists are not specific, and may be generated from any number of sources. The system word list used to be /usr/dict/words. For compatibility, software should check that location if /usr/share/dict/words does not exist. AUTHOR
Word lists are collected and maintained by various authors. The Debian English word lists are built from the SCOWL (Spell- Checker Ori- ented Word Lists) package, whose upstream editor is Kevin Atkinson <kevina@users.sourceforge.net>. Debian 16 June 2003 british-english(5)
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy