LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2012, 08:45 PM   #1
pierceogden
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
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!!!

Last edited by pierceogden; 04-03-2012 at 08:46 PM. Reason: make it more readable
 
Old 04-03-2012, 09:00 PM   #2
pierceogden
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
figured it out, I needed a printf in the 1st awk command!
 
Old 04-05-2012, 12:33 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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

Last edited by David the H.; 04-05-2012 at 12:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash; awk or sed output to variable: how keep newline at end of each output line porphyry5 Programming 3 06-10-2011 05:50 PM
Awk script - Converting newline chars sleeper0110 Programming 6 06-05-2009 06:50 PM
Inserting Multiple Lines (with newline) using sed or awk hal8000b Programming 1 03-08-2009 05:21 PM
Awk newline problem CelticSoul Linux - General 5 05-03-2006 09:00 PM
problems with newline in awk test Programming 6 05-02-2004 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration