match sentence and word adn fetch similar words in alist


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting match sentence and word adn fetch similar words in alist
# 1  
Old 08-03-2012
match sentence and word adn fetch similar words in alist

Hi all,


I have ot match sentence list and word list anf fetch similar words in a separate file

Quote:
1 file with 2 columns

xyz it is used in blood pressure
abc it is used in cardiac disease
second file with 2 columns
Quote:
blood pressure
diabetes
So I want the output shuld be 2 columns like this

Quote:
xyz blood pressure

Last edited by manigrover; 08-03-2012 at 04:50 AM..
# 2  
Old 08-03-2012
How about this:
Code:
awk '
    NR==FNR{a[$2]=$1;next}
    $1 in a{$1=a[$1]" "$1;print;next}
    $1" "$2 in a{$2=$1" "$2;$1=a[$2];print}' FS=" it is used in " file1 FS=" " file2

# 3  
Old 08-03-2012
check

Hi

It's checking the whole sentenece
and printing
Quote:
xyz it is used in blood pressure
which is very different form what I want

as I want

Quote:
xyz blood pressur
e
# 4  
Old 08-05-2012
Sorry typo try:

Code:
awk '     
   NR==FNR{a[$2]=$1;next}     
   $1 in a{$1=a[$1]" "$1;print;next}     
   $1" "$2 in a{$2=$1" "$2;$1=a[$2];print}' FS=" it is used in " file1 OFS=" " file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch lines between 1st and 4th similar pattern

Hi Folks, I have a big file that looks like below ========== kjhjl kjlklkkhcgflj fgf ========== xsww23edc ccdde3rfv ceerfcc vff4 ========== zaq12wsx xsw23edc ========== ========== (3 Replies)
Discussion started by: jayadanabalan
3 Replies

2. Shell Programming and Scripting

Print one sentence 40 to 50 words end with period in a file

Hi All, Is there another way to achieve this? how get short phrase in a sentence with character count of 100 to 155 words end with period but don't end something like 50,000. . Here's my current script but the output is not good. This will use for my snippets or preview. grep... (6 Replies)
Discussion started by: lxdorney
6 Replies

3. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

4. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

5. Shell Programming and Scripting

Match words and fetch data in front of it in second column

Hi all, I have 2 files one file contain data like this in one column AST3 GSTY4 JST3 second file containign data like this in 2 columns AST3(PAXXX),GSTY4(PAXXY) it is used in diabetes KST4 it is used in blood... (6 Replies)
Discussion started by: manigrover
6 Replies

6. Shell Programming and Scripting

Match the word or words and fetch the entries

Hi all, I have 7 words Now I have 1 file which contain data in large number of rows and columns and 6th column contain any of these words or may be more than one words among above 7 words: I want script should search for the above mentioned 7 words in the 6th column ... (9 Replies)
Discussion started by: manigrover
9 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. Shell Programming and Scripting

Extract a word from sentence

$SET_PARAMS='-param Run_Type_Parm=Month -param Portfolio_Parm="997" -param From_Date_Parm="2011-08-09"' Want to extract the value of "Portfolio_Parm" from $SET_PARAMS i.e in the above case "997" & assigned to new variable. The existence order of "Portfolio"Parm" can change, but the name... (2 Replies)
Discussion started by: SujeethP
2 Replies

9. Shell Programming and Scripting

Truncate the word from a sentence

Hi, The first line of a file is as follows: example.4ge v.45352 Report for April 28 May 2010 I need to remove the word example.4ge v.45353 from that line. I used the following command to truncate it sed 's/example.4ge v.45352//g' $filename But here the version number 45352 may... (4 Replies)
Discussion started by: Kattoor
4 Replies

10. Shell Programming and Scripting

Print all the words after a match word

Hi, I want to print all words till the last word after the match of "ERROR" word. For e.g. I'll get an sqlplus error with e.g. 1 $ ./calltest_fn.ksh var test_var:=test_fn1; calltest_fn.ksh file1 file2 file3 ERROR at line 4: ORA-06550: line 4, column 11: PLS-00201: identifier... (5 Replies)
Discussion started by: dips_ag
5 Replies
Login or Register to Ask a Question