LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   why is my awk command printing on a newline?????? (https://www.linuxquestions.org/questions/linux-newbie-8/why-is-my-awk-command-printing-on-a-newline-937990/)

pierceogden 04-03-2012 08:45 PM

why is my awk command printing on a newline??????
 
I am creating a table as follows

Code:

pdb  uniprot  #ligands  Energy 
---------------------------------------
2h7l  P0A5Y6  500
-32.893
3e37  Q8K2I1  501
-38.5512
1bcd  P00918  505
-26.5727

the negative number is an average of a column of numbers from a separate file. my code is as follows

Code:

#!bin/bash



printf "pdb  uniprot  #ligands  Energy  \n"
echo '---------------------------------------'


while read pdbs
do
        cd rn$pdbs
        while read uni
        do
                printf $pdbs
                printf "  "
                cd run.$uni
                printf $uni
                printf "  "
                cd 1.A
                for a in *.gz
                do
                        gzip -d $a
                done
       
                        grep -i 'remark c' test.eel1 >        out.txt
                        wc -l out.txt > a
                        awk '{print $1}' a
                        awk '{ total +=$5; count++ } END { printf total/count }' out.txt # creating new line???
               
                printf "\n"
                cd ../..
        done < uni_codes.txt
       
       

cd ..



done < $1

I have tried print & printf statements. I have also tried saving the output of the awk command and cat the awk output file. I also tried adding a <| tr -d '\n'> after the awk command, which didn't work Any ideas? my table doesn't really make sense with the numbers down there. Thanks!!!

pierceogden 04-03-2012 09:00 PM

figured it out, I needed a printf in the 1st awk command!

David the H. 04-05-2012 12:33 PM

I just made a post in your other thread about the use of printf. Please learn how to use it correctly.

Also note that the printf in awk has a slightly different syntax from bash's version (arguments are separated by commas), and is capable of doing more (particularly when working with numbers, due to the full floating-point arithmetic engine). awk's print command is pretty much equal to bash's echo.


Speaking of which, I should've mentioned before, you can also use echo -n in bash to print a simple string without a newline (equivalent to "printf '%s'").

Edit: see here for details on gawk's version of printf.
http://www.gnu.org/software/gawk/man...tf.html#Printf


All times are GMT -5. The time now is 11:46 PM.