Sponsored Content
Full Discussion: formatting output using echo
Top Forums Shell Programming and Scripting formatting output using echo Post 302275328 by cfajohnson on Friday 9th of January 2009 09:16:22 PM
Old 01-09-2009
Quote:
Originally Posted by npatwardhan
i have the following script:

That is only a snippet of a script; it cannot be run as is.

Many variables are not initialized.
Quote:
Code:
while [ $j -lt $outer ];do


Neither $j nor $outer is initialized.
Quote:
Code:
b=${ARRAY2[j]}
i=0
while [ $i -lt $count ];do


$count is not initialized.
Quote:
Code:
a=${ARRAY1[k]}
fin[i]=`echo $a - $b | bc`


What are the values of $a and $b? Are they integers? If so, you don't need to call an external command.
Quote:
Code:
echo -e  "${fin[i]}," >> try


Is this what you want:

Code:
printf "%s," "${fin[i]}," >> try

Quote:
Code:
((i++))
((k++))


It's better to use the standard format for arithmetic:

Code:
i=$(( $i + 1 ))
k=$(( $k + 1 ))

Quote:
Code:
done
echo -n >> try
#add statement to format output here
#printf "\t" >> try
#echo -e '\t' >> nik
((j++))


See above.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting the output

Hi all, Have the following code(1) producing the results(2 & 3). Would like to know if there is a way to format the two reports created in a similar fashion. IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt However when I attempt to do the same on... (7 Replies)
Discussion started by: Cameron
7 Replies

2. Shell Programming and Scripting

formatting output

Hi need some advice.. #grep -i hostname test.csv (gives the below output) HOSTNAME,name,host_test,,,,,,,, Now I need to format the above output as below. HOSTNAME: name=host_test Any easy way of doing this using awk or sed or printf? (4 Replies)
Discussion started by: balaji_prk
4 Replies

3. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

4. Shell Programming and Scripting

more help with formatting ls output...

Ok, for a fun project, my goal is to replicate the style of "catalog" on an old apple ] *A 002 SOMEAPPLESOFTFILE B 004 SOMEFILE T 006 SOMETEXT I 002 SOMEINTEGERFILE The first character is either " " or "*" depending on if the file is locked or not. Next is the filetype, so in... (1 Reply)
Discussion started by: patrick99e99
1 Replies

5. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

6. Shell Programming and Scripting

formatting output

my script is as follows cnt=`ps -ef |grep pmon|grep -v grep|awk 'END {{print NR}}'` cnt2=`ps -ef |grep tns|grep -v grep|awk 'END {{print NR}}'` if then if then rman target/ catalog recdb/recdb@recdb cmdfile report_need_backup.sql > report_need_backup.txt ... (1 Reply)
Discussion started by: swkambli
1 Replies

7. Shell Programming and Scripting

Formatting output

Hi, I have a file like this -------------------------- 1 aaa xxx 55 -------------------------- 1 aaa www 32 -------------------------- 2 bbb yyy 11 -------------------------- 2 bbb zzz 34 ------------------------- 2 bbb ttt ... (3 Replies)
Discussion started by: tdev457
3 Replies

8. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

9. Shell Programming and Scripting

Formatting echo o/p

Hi Team, Need a small help. I want to format my echo o/p. let say echo " helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo " I want o/p to be displayed in below format helo helo helo helo helo helo helo helo helo helo helo helo... (6 Replies)
Discussion started by: gvkumar25
6 Replies

10. Shell Programming and Scripting

Output formatting

Hi , can anyone help me in this Input file Name= XYZ Company= ALPHA City= Stockhomn Equipment=computer Country=Sweden Name=MNC Company=Beta City=Kaulampur Equipment=computer Country=Malaysia Name=JVC Company=gamma City=Kiruna (3 Replies)
Discussion started by: swets
3 Replies
All times are GMT -4. The time now is 01:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy