A mistake in awk command I used to parse numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A mistake in awk command I used to parse numbers
# 1  
Old 02-20-2011
A mistake in awk command I used to parse numbers

Hi

I have a big file with a certain pattern (shown below) from which I need to parse out some digits in tabular format.

The format of the file is: '-' indicates text which doesn't to be parsed
Code:
# Output of huzzle for sequence file 1000.Clade1.html
  - - - -- ------- -----------------------------------------
  ---------------------------------------------------------
 ------------------------------------------------------------
 ---------------------------------------------------------------
# SCORE     7.951      0.6909        -0.32       0.0026   
  ------------------------------------------------------------
 -------------------------------------------------------------
----------------------------------------------------------------
# Output of huzzle for sequence file 1001.Clade1.html
  - - - -- ------- -----------------------------------------
  ---------------------------------------------------------
 ------------------------------------------------------------
 ---------------------------------------------------------------
# SCORE     7.951      0.0909        -0.32       0.0026   
  ------------------------------------------------------------
 -------------------------------------------------------------
----------------------------------------------------------------
# Output of huzzle for sequence file 1002.Clade1.html
  - - - -- ------- -----------------------------------------
  ---------------------------------------------------------
 ------------------------------------------------------------
 ---------------------------------------------------------------
# SCORE     7.951      0.07909        -0.32       0.0026   
  ------------------------------------------------------------
 -------------------------------------------------------------
----------------------------------------------------------------
# Output of huzzle for sequence file 1003.Clade1.html
  - - - -- ------- -----------------------------------------
  ---------------------------------------------------------
 ------------------------------------------------------------
 ---------------------------------------------------------------
# SCORE     7.951      0.0109        -0.32       0.0026   
  ------------------------------------------------------------
 -------------------------------------------------------------
----------------------------------------------------------------



What numbers I need to parse out is; for example the 1003 from "Output of huzzle for sequence file 1003.Clade1.html" and 0.0109 from "SCORE 7.951 0.0109 -0.32 0.0026"..like wise from all those patterns

So that I would get the tab delimited file as:
Code:
1000 0.6909
1001 0.0909
1002 0.07909
1003 0.0109

I tried with the following awk code but I am not getting it correctly
Code:
awk '
/^Output of huzzle for sequence file/ {r1=$7;gsub(/\..*/,"",r1)}
/^SCORE/ {r2=$2;print r1,r2}' my file

Please let me know what might be the error.

LA
# 2  
Old 02-20-2011
Hi,

From your awk script:
1.- The '^' char means the beginning of line and there is a '#' char before of what you wrote.
2.- Awk splits fields with spaces, so the first digit of your output is the eigth and the score is the fourth.

Test if it works with those changes:
Code:
$ awk '/Output of huzzle for sequence file/ { r1 = $8; gsub(/\..*/, "", r1) } /SCORE/ { r2 = $4; print r1, r2 }' infile
1000 0.6909
1001 0.0909
1002 0.07909
1003 0.0109

Regards,
Birei
# 3  
Old 02-20-2011
Code:
awk '/Output of huzzle for sequence file/ {split($8,a,".")} /SCORE/ {print a[1], $4 }' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse for 2 numbers in large single line

Hi All, I am writing a script in which I need to gather 2 numbers for 'total' and 'successful'. The goal is to compare the two numbers and if they are not equal, rerun the task until all are successful. I'm thinking the best way will be with awk or sed, but I really don't know where to begin... (8 Replies)
Discussion started by: hburnswell
8 Replies

2. Shell Programming and Scripting

awk syntax mistake doubles desired output

I am trying to add a line to a BASH shell script to print out a large variable length table on a web page. I am very new to this obviously, but I tried this with awk and it prints out every line twice. What I am doing wrong? echo "1^2^3%4^5^6%7^8^9%" | awk 'BEGIN { RS="%"; FS="^"; } {for (i =... (6 Replies)
Discussion started by: awknewb123
6 Replies

3. Shell Programming and Scripting

Parse ouput within an AWK Command

I have a script that I am writing to parse the output of information from a command. Here is one of the lines of the output exported into the variable OUTPUT: export OUTPUT=”name_of_system,0,5,9,55,ip_address,another_value,/PATH/OF/A/VALUE/I/NEED" I can get the output I need... (5 Replies)
Discussion started by: jake0391S
5 Replies

4. Shell Programming and Scripting

AWK Command parse a file based on string.

AWK Command parse a file based on string. I am trying to write a shell script to parse a file based on a string and move the content of the file to another file. Here is scenario. File content below Mime-Version: 1.0 Content-Type: multipart/mixed; ... (2 Replies)
Discussion started by: aakishore
2 Replies

5. Shell Programming and Scripting

How to evaluate a string of numbers in the same command of AWK

Hi, I am trying to do evaluate one numerical string after substitution. ++++++++++++++++== What I have = "7.04+2.3Xlog(0.72e-6X1.0e6)X1.9596" What I need = evaluate 7.04+2.3*log(0.72e-6*1.0e6)*1.9596 = 5.55941 what I am doing; echo "7.04+2.3Xlog(0.72e-6X1.0e6)X1.9596" | awk... (2 Replies)
Discussion started by: vivek_shm74
2 Replies

6. Shell Programming and Scripting

Problem with sub command (awk) and numbers

Hi, I am trying to perform a simple soustraction between two floating numbers and cannot get it done for some reason due to the use of the sub command. The following is the straight-forward result of the soustraction: $ echo | gawk '{a=968;b=967.99;c=a-b;print c}' ... (2 Replies)
Discussion started by: Indalecio
2 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

awk/sed Command: To Parse Stament between 2 numbers

Hi, I need an awk command that would parse the below expression Input Format 1 'Stmt1 ............................'2 'Stmt2 ............................'3 'Stmt3 ............................'4 'Stmt4 ............................'5 'Stmt5 ............................'6 'Stmt6... (1 Reply)
Discussion started by: rajan_san
1 Replies

9. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

10. Shell Programming and Scripting

How to parse large numbers of shell scripts

I am trying to parse hundreds of shell scripts to determine how they related to each other. Ideally for every script, I would get an output of: What other scripts it calls What files it reads Environment variables it accesses Any ideas on how to do this? TIA! (2 Replies)
Discussion started by: bliss
2 Replies
Login or Register to Ask a Question