Find matches and write the data before it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find matches and write the data before it
# 8  
Old 11-08-2012
Request to check

Yes, it didnt wrk as output is just first file and

the sample which I provided is above is exactly from real file

shall I attach file?

let me know but its same as my sample provided above.
# 9  
Old 11-08-2012
Quote:
Originally Posted by Priyanka Chopra
Yes, it didnt wrk as output is just first file and

the sample which I provided is above is exactly from real file
I don't know what you are trying.

Please check..

Code:
$ cat file1
F2
B2
CAD
KGM
HTC
CSP

Code:
$ cat file2
F2 XYZ CDT CAD          it is part of agriculture    it is part of university   it is part of ...             it is used for....

KGM HTC CSP      it is part of agriculture    it is part of university   it is part of ...             it is used for....

Code:
$ awk 'NR==FNR{X[$1]=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X[P[i]]){print P[i],$0}}}' file1 FS="  +" file2
F2           it is part of agriculture    it is part of university   it is part of ...             it is used for....
CAD           it is part of agriculture    it is part of university   it is part of ...             it is used for....
KGM       it is part of agriculture    it is part of university   it is part of ...             it is used for....
HTC       it is part of agriculture    it is part of university   it is part of ...             it is used for....
CSP       it is part of agriculture    it is part of university   it is part of ...             it is used for....

Is this what you want..?

I hope this helpsSmilie

pamu
# 10  
Old 11-08-2012
Hi

It seems some error

Finally I am attaching both BD(first) 1diseasedrug(second) files and output file(see)

Pleas check it

these are just part as the files are big and I also got one error
Code:
bash-3.2$ awk 'NR==FNR{X[$1]=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X[P[i]]){print P[i],$0}}}' BD FS="  +" diseasedrugbank >see
awk: (FILENAME=diseasedrugbank FNR=471) fatal: Unmatched ( or \(: /DRD2 ADRA1A  Droperidol      DHBP    DRD2 ADRA1A     The exact mechanism of action is unknown, however, droperidol causes a CNS depression at subcortical levels of the brain, midbrain, and brainstem reticular formation. It may antagonize the actions of glutamic acid within the extrapyramidal system. It may also inhibit cathecolamine receptors and the reuptake of neurotransmiters and has strong central antidopaminergic action and weak central anticholinergic action. It can also produce ganglionic blockade and reduced affective response. The main actions seem to stem from its potent Dopamine(2) receptor antagonism with minor antagonistic effects on alpha-1 adrenergic receptors as well.      A butyrophenone with general properties similar to those of haloperidol. It is used in conjunction with an opioid analgesic such as fentanyl to maintain the patient in a calm state of neuroleptanalgesia with indifference to surroundings but still able to cooperate with the surgeon. It is also used as a premedicant, as an antiemetic, and for the control of agitation in acute psychoses. (From Martindale, The Extra/
bash-3.2$

so output is not as expected in these files
# 11  
Old 11-08-2012
From your sample file it looks like your file2 has no pattern to get the required result.

still try using "\t"


Code:
awk 'NR==FNR{X[$1]=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X[P[i]]){print P[i],$0}}}' file1 FS="\t" file2

# 12  
Old 11-16-2012
Hi Pamu

This semed to be a good code I apllied to many other files and suddenly I realise it didnt wrok fo rmy many other files and my hard goes waste!

Becasuse it was matching with just first entry of second file

Kindly help me as I have to again run on all those files.

I have attachedone of those files

May be it has happened becuase second file contain first oclumn with entire separarated by comma.........

sorry for inconvenience.

Kindly guide meSmilie
# 13  
Old 11-16-2012
I doesnt wrk even on these once

first file pHAMRGKBT2D

second file Pharmgkbdrugdisease3.txt SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a text and if condition matches then replace it

Need a script that can find text in a file and replace it accordingly. This is the file I have: while IFS=',' read -r f1 f2 f3 do { nohup /home/testuser/dbmaintenance/sys_offline_maintenance.sh $f1 $f2 $f3 > $f2.out & } done < "/home/testuser/dbmaintenance/week1offlineserver.txt" In... (4 Replies)
Discussion started by: singhhe
4 Replies

2. Shell Programming and Scripting

Find Data in test file and write each out to a line

I have a .csv file that has been create from a google form and I need to extract the data from it that has been entered by users. The CSV will have anywhere between 100 and 1000 lines which comprise entr data for a sports carnival A few typical line is shown here to show the problem I have ... (19 Replies)
Discussion started by: kcpoole
19 Replies

3. Shell Programming and Scripting

Find common entries in 2 list and write data before it

Hi all, I have 2 files: second file I want if entries in one file will match in other file. It shuld wite approve before it so output shuld be (1 Reply)
Discussion started by: manigrover
1 Replies

4. Shell Programming and Scripting

zgrep cannot find all matches

$ cat 1.csv abc in csv $ cat 1.mnf abc in mnf $ zip 1.zip 1.csv 1.mnf adding: 1.csv (stored 0%) adding: 1.mnf (stored 0%) $ zgrep abc 1.zip abc in csv How come zgrep cannot find "abc in mnf"? Thanks in advance. (5 Replies)
Discussion started by: carloszhang
5 Replies

5. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

6. Shell Programming and Scripting

Find directories that contains more than n matches of a certain filename

I need to construct a command that finds directories which contains more than n matches of a certain filename. E.g. I have many directories at different locations and want to find all directories that has 2 or more .dat-files. I thought of using find and maybe the exec parameter to issue an... (5 Replies)
Discussion started by: odyssey
5 Replies

7. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

8. Shell Programming and Scripting

find matches in file

Hi, im have log file ~100000 lines, 192.168.29.1 at 10/08/09 13:58:55 192.168.60.1 at 10/08/09 14:11:28 192.168.58.171 at 10/08/09 14:12:45 192.168.61.12 at 10/08/09 14:15:44 192.168.60.1 at 10/08/09 14:16:36 192.168.60.1 at 10/08/09 14:17:43 192.168.61.12 at 10/08/09 14:18:08... (9 Replies)
Discussion started by: Trump
9 Replies

9. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

10. Shell Programming and Scripting

Extarcting data from a file that matches two different patterns

Say I have data like shown below. I want all the data that contains XXXX and where it finds XXXX then I also want the Timestamp and the Error fields. I have tried egrep "XXXX|Timestamp" > test.txt. That pulls out the data correctly but gives me two records for each message and it also pulls the... (4 Replies)
Discussion started by: gugs
4 Replies
Login or Register to Ask a Question