Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-03-2012, 09:45 PM   #1
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

pdb   uniprot  #ligands   Energy  
2h7l  P0A5Y6   500
3e37  Q8K2I1   501
1bcd  P00918   505
the negative number is an average of a column of numbers from a separate file. my code is as follows


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

while read pdbs
	cd rn$pdbs
	while read uni
		printf $pdbs
		printf "  "
		cd run.$uni
		printf $uni
		printf "   "
		cd 1.A
		for a in *.gz 
			gzip -d $a
			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 09:46 PM. Reason: make it more readable
Old 04-03-2012, 10:00 PM   #2
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, 01:33 PM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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.

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:50 PM
Awk script - Converting newline chars sleeper0110 Programming 6 06-05-2009 07:50 PM
Inserting Multiple Lines (with newline) using sed or awk hal8000b Programming 1 03-08-2009 06:21 PM
Awk newline problem CelticSoul Linux - General 5 05-03-2006 10:00 PM
problems with newline in awk test Programming 6 05-02-2004 03:33 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:08 AM.

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