|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Retrieve many entries using awk
Hi all I have a problem similar to someone else while getting output using awk and retrieving certain entries. From the attached sample file of big file I have to retreive following headings in columns from each drug card as there are many drug cards.. # Drug_Target_.*_Gene_Name # Brand_Name # Generic_Name # Drug_Type # Indication #Mechanism_ Of_ Action Using below code, my output is a bit random and wired even though some part are correct as mehanism keep on repeating agian and again some time starts with the next line rather than being fit in columns Brand name keep going wrong sometime!! I am trying to retreive Code:
awk 'k>0 {if (a[k] && k==2) {print a[1]":"a[2]":"a[3]":"a[4]":"a[5]":"a]6]; a[1]=a[2]=a[3]=a[4]=a[5]=a[6]"";} a[k]=a[k]?a[k]","$0:$0; k=0;} /^# / {k=1;} /^# Generic/ {k=1;} /^# Brand_Name/ {k=2;} /^# Drug_Type/ {k=3;} /^# Indication/ {k=5;} /^# Mechanism_ Of_ Action / {k=6;} END {if (a[1]) print a[1]":"a[2]":"a[3]":"a[4]":"a[5]":"a[6];}' drugbank.txt >drugbanknew.txtCan anybody check my code in his/her system and let me know wrong things ?High thanks |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Not sure I understand what you want to achieve. Pls post desired output.
BTW, your script above contains a few typos... |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Rudi
I have to fetch above mentioned bold headings in my first post as columns in my expected output. This input file is sample of my big input file which contain many drug cards So, My out put shoulbe like following six coulmns F2 lepirudin refuldan approved " sentence under indication" "sentence under machanism of action" As my real input file is big so there will be many rows with different names like this and with my current code these rows are overlapping! |
|
#4
|
|||
|
|||
|
see my post #2.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Sorry I was not able to get your post#2 could you please explain which one it is.
High thanks for this |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Post #2 Code:
Not sure I understand what you want to achieve. Pls post desired output. You have sample input, but we would like to see sample output. What do you like to get from your script. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi For my above attached sample input expected output is 6 columns like this: Code:
F2 Lepirudin Refludan Approved For the treatment of heparin-induced thrombocytopenia Lepirudin forms a stable non-covalent complex with alpha-thrombin, thereby abolishing its ability to cleave fibrinogen and initiate the clotting cascade. The inhibition of thrombin prevents the blood clotting cascade. here 6 columns represent following headings from my input file: Code:
# Drug_Target_.*_Gene_Name # Brand_Name # Generic_Name # Drug_Type # Indication #Mechanism_ Of_ Action In the same way I have a big file wiht many drug cards and each drug card containing these entries which I have to fetch in 6 columns. I have also mentioned the code which I am using. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Retrieve printer detail - AWK | sraj142 | Shell Programming and Scripting | 3 | 05-30-2012 04:29 AM |
| awk to retrieve the particular value from a same list of xml tags | mjavalkar | Shell Programming and Scripting | 4 | 05-01-2012 04:12 PM |
| How to retrieve digital string using sed or awk | victorcheung | Shell Programming and Scripting | 3 | 08-12-2010 06:49 AM |
| How to retrieve data using awk command | prasad4004 | Shell Programming and Scripting | 5 | 07-30-2010 04:08 AM |
| retrieve lines using sed, grep or awk | learning_linux | UNIX for Dummies Questions & Answers | 3 | 03-25-2009 05:51 AM |
|
|