Retrieve many entries using awk | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Retrieve many entries using awk

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-30-2012
Priyanka Chopra Priyanka Chopra is offline
Banned
 
Join Date: Nov 2012
Last Activity: 7 June 2013, 1:42 AM EDT
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
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.txt

Can anybody check my code in his/her system and let me know wrong things ?High thanks
Attached Files
File Type: txt Input file.txt (15.8 KB, 24 views)
Sponsored Links
    #2  
Old 11-30-2012
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 21 October 2014, 9:27 AM EDT
Location: Aachen, Germany
Posts: 4,406
Thanks: 73
Thanked 1,076 Times in 1,015 Posts
Not sure I understand what you want to achieve. Pls post desired output.

BTW, your script above contains a few typos...
Sponsored Links
    #3  
Old 12-02-2012
Priyanka Chopra Priyanka Chopra is offline
Banned
 
Join Date: Nov 2012
Last Activity: 7 June 2013, 1:42 AM EDT
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
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  
Old 12-02-2012
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 21 October 2014, 9:27 AM EDT
Location: Aachen, Germany
Posts: 4,406
Thanks: 73
Thanked 1,076 Times in 1,015 Posts
see my post #2.
Sponsored Links
    #5  
Old 12-03-2012
Priyanka Chopra Priyanka Chopra is offline
Banned
 
Join Date: Nov 2012
Last Activity: 7 June 2013, 1:42 AM EDT
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
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  
Old 12-04-2012
Jotne's Avatar
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
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  
Old 12-09-2012
Priyanka Chopra Priyanka Chopra is offline
Banned
 
Join Date: Nov 2012
Last Activity: 7 June 2013, 1:42 AM EDT
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 12:45 PM.