Sponsored Content
Top Forums Shell Programming and Scripting Retrieve many entries using awk Post 302737945 by Priyanka Chopra on Friday 30th of November 2012 05:17:13 AM
Old 11-30-2012
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
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

retrieve lines using sed, grep or awk

Hi, I'm looking for a command to retrieve a block of lines using sed or grep, probably awk if that can do the job. In below example, By searching for words "Third line2" i'm expecting to retrieve the full block starting with 'BEGIN' and ending with 'END' of the search. Example: ... (3 Replies)
Discussion started by: learning_linux
3 Replies

2. Shell Programming and Scripting

How to retrieve data using awk command

I have a txt file with below data (textfile1.txt) select col1, col2 from Schema_Name.Table_Name1 select * from Schema_Name.Table_Name2 select col1, col2, col3 from Schema_Name.Table_Name3 select col1 from Schema_Name.Table_Name4 My output should look like Table_Name1 Table_Name2... (5 Replies)
Discussion started by: prasad4004
5 Replies

3. Shell Programming and Scripting

How to retrieve digital string using sed or awk

Hi, I have filename in the following format: YUENLONG_20070818.DMP HK_20070818_V0.DMP WANCHAI_20070820.DMP KWUNTONG_20070820_V0.DMP How to retrieve only the digital part with sed or awk and return the following format: 20070818 20070818 20070820 20070820 Thanks! Victor (3 Replies)
Discussion started by: victorcheung
3 Replies

4. Shell Programming and Scripting

sed/awk to retrieve max year in column

I am trying to retrieve that max 'year' in a text file that is delimited by tilde (~). It is the second column and the values may be in Char format (double quoted) and have duplicate values. Please help. (4 Replies)
Discussion started by: CKT_newbie88
4 Replies

5. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

6. Shell Programming and Scripting

awk to retrieve the particular value from a same list of xml tags

Hi All, I have the following code in one of my xml file: <com:parameter> <com:name>secretKey</com:name> <com:value>31XA874821172E89B00B1C</com:value> </com:parameter> <com:parameter> <com:name>tryDisinfect</com:name> <com:value>false</com:value> </com:parameter> <com:parameter>... (4 Replies)
Discussion started by: mjavalkar
4 Replies

7. Shell Programming and Scripting

Retrieve printer detail - AWK

Hi All, For some reason, I need to have the printer detail from the AIX. Following are the part of /etc/qconfig and /etc/hosts. Can any one of you please help me with an awk some other option to get the detail ? I have mentioned the required output format at the end. /etc/qconfig s63lb1: ... (3 Replies)
Discussion started by: sraj142
3 Replies

8. Shell Programming and Scripting

awk - To retrieve an expression from the last line containing a pattern

Hi All, I'm new on this forum, and i'm trying since several days to find out a way to retrieve a expression from the last line containing a pattern. Could you please help me with this ? E.g. The file is containing the following lines 08/05 17:33:47 STAT1 Response(22) is... (4 Replies)
Discussion started by: Antonio Fargas
4 Replies

9. UNIX for Beginners Questions & Answers

awk command to retrieve record 23 and 89 from UNIX file

Hi Everyone, I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this? Regards Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

10. Homework & Coursework Questions

awk command to retrieve record 23 and 89 from UNIX file

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 am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies
NUMSUM(1)						User Contributed Perl Documentation						 NUMSUM(1)

NAME
numsum - numsum program file SYNOPSIS
numsum [-iIcdhrsvxy] <FILE> | numsum [-iIcdhrsvxy] (Input on STDIN from pipeline.) numsum [-iIcdhrsvxy] (Input on STDIN. Use Ctrl-D to stop.) DESCRIPTION
numsum will take all the numbers on stdin and return the sum of those numbers. Currently it only processes the first number on each line. Besides positive numbers, it also handles negative numbers and numbers with decimals. OPTIONS
-i Only return the integer portion of the final sum. -I Only return the decimal portion of the final sum. -c Print out the sum of each column. -r Print out the sum of each row. -x <n> Specify a comma seperated list of columns to print. -y <n> Specify a comma seperated list of rows to print. -s <string> Specify a string to use as a seperator for columns. This defaults to be consecutive whitespace (s+). -h Help: You're looking at it. -V Increase verbosity. -d Debug mode. For developers -q Quiet mode, don't print any warnings. EXAMPLES
Simply add up the numbers in a file. $ numsum numbers.txt 4315 Enter your own numbers on STDIN. The last number is the answer. $ numsum 4 21 98 100 223 Use it in a command pipeline. $ ls -1s | grep .mp3 | numsum -c -x 5 72288 Add up the total byte count in a http log file. $ cat access_log | awk {'print $10'} numsum or numsum -c -x 10 access_log Add up the columns of numbers of a file. $ cat columns 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 $ numsum -c columns 15 40 65 90 115 Add up the 1st, 2nd and 5th columns only. $ numsum -c -x 1,2,5 columns 15 40 115 Add up the rows of numbers of a file. $ numsum -r columns 55 60 65 70 75 Add up the 2nd and 4th rows. $ numsum -r -y 2,4 columns 60 70 SEE ALSO
numaverage(1), numbound(1), numinterval(1), numnormalize(1), numgrep(1), numprocess(1), numrandom(1), numrange(1), numround(1) COPYRIGHT
numsum is part of the num-utils package, which is copyrighted by Suso Banderas and released under the GPL license. Please read the COPYING and LICENSE files that came with the num-utils package Developers can read the GOALS file and contact me about providing submitions or help for the project. MORE INFO
More info on numsum can be found at: http://suso.suso.org/programs/num-utils/ perl v5.10.1 2009-10-31 NUMSUM(1)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy