Sponsored Content
Top Forums Shell Programming and Scripting Print loop output on same line dynamically Post 303017212 by Sumanthsv on Friday 11th of May 2018 01:58:04 AM
Old 05-11-2018
Print loop output on same line dynamically

Hi,

I am trying to print copy percentage completion dynamically by using the script below,

Code:
#!/bin/bash
dest_size=0
orig_size=`du -sk $sourcefile | awk '{print $1}'`
while [ $orig_size -gt $dest_size ] ; do
   dest_size=`du -sk  $destfile | awk '{print $1}'`
coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size" | bc`
echo "$coyp_percentage"
sleep 1
done

From above code am getting completion percentage on newline as below,

Code:
.84
1.97
3.38
8.75
15.81
23.72

But I need the output on same line with space separated dynamically.

Any help on this..

Note: Do i need to use OFS for this?

OS_ver:Sol_11.3x86
shell=bash

TIA
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do i print this output all on the same line?

I have this simple script which gives info on HBA ports. How do i get it all to print on the same line? !#/bin/ksh TMP_INFOFILE=/tmp/tmpfile if ; then rm -f $TMP_INFOFILE touch $TMP_INFOFILE fi PORT_INFOFILE=/tmp/aa if ; then rm -f $PORT_INFOFILE ... (1 Reply)
Discussion started by: rcon1
1 Replies

2. Shell Programming and Scripting

Print in New line in loop

Hi , i want to print the output in line by line while read LINE do echo $LINE | grep UCM | egrep '(Shutdown|Unavailable)' echo $LINE | grep SRBr | egrep '(Shutdown|Unavailable)' echo $LINE | grep SRP| egrep '(Shutdown|Unavailable)' echo $LINE | grep OM | grep JMS|... (7 Replies)
Discussion started by: navsan
7 Replies

3. Shell Programming and Scripting

Print for loop variable in output too

Hi, This is my input file cat input chr1:100-200 chr1:220-300 chr1:300-400 Now, I would like to run a program that will take each of the input record for i in `cat input`; do program $i | wc -l;done the output will be something like 10 20 30 But, I would like to print the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

4. UNIX for Dummies Questions & Answers

Print each output of loop in new column using awk or shell

I have this output from a loop a11 1,2 3,4 5,6 7,8 12,8 5,4 3,6 a12 10,11 12,13 15,18 20,22 a13 ... (3 Replies)
Discussion started by: maryre89
3 Replies

5. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

6. Linux

Print line 1 if line 3 matches of the output

Hi I want to extend following command so that on the basis of "Branch: ****" on the third line I can grep and print name of the file on the first line. cat .labellog.emd | grep DA2458A7962276A7E040E50A0DC06459 | cut -d " " -f2 | grep -v branch_name | xargs -I file <command to describe> file ... (1 Reply)
Discussion started by: ezee
1 Replies

7. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

8. UNIX for Beginners Questions & Answers

Loop through directory and print on line

In the bash below I am trying to loop through all the R1.gz in a directory (always 1), store them in ARRAY, and cut them before the second _. That is being done but I can't seem to print then one a single line seperated by a space. Is the below the best way or is there a better solution? Thank you... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. Shell Programming and Scripting

Echo print on same line while loop using variable

Currently using below script but echo it print the output in two line. Input file all-vm-final-2.txt CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4 CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4 CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4 DEALA08762 SDDC_LDC... (3 Replies)
Discussion started by: ranjancom2000
3 Replies
librrd(3)							      rrdtool								 librrd(3)

NAME
librrd - RRD library functions DESCRIPTION
librrd contains most of the functionality in RRDTool. The command line utilities and language bindings are often just wrappers around the code contained in librrd. This manual page documents the librrd API. NOTE: This document is a work in progress, and should be considered incomplete as long as this warning persists. For more information about the librrd functions, always consult the source code. CORE FUNCTIONS
rrd_dump_cb_r(char *filename, int opt_header, rrd_output_callback_t cb, void *user) In some situations it is necessary to get the output of "rrd_dump" without writing it to a file or the standard output. In such cases an application can ask rrd_dump_cb_r to call an user-defined function each time there is output to be stored somewhere. This can be used, to e.g. directly feed an XML parser with the dumped output or transfer the resulting string in memory. The arguments for rrd_dump_cb_r are the same as for rrd_dump_opt_r except that the output filename parameter is replaced by the user- defined callback function and an additional parameter for the callback function that is passed untouched, i.e. to store information about the callback state needed for the user-defined callback to function properly. Recent versions of rrd_dump_opt_r internally use this callback mechanism to write their output to the file provided by the user. size_t rrd_dump_opt_cb_fileout( const void *data, size_t len, void *user) { return fwrite(data, 1, len, (FILE *)user); } The associated call for rrd_dump_cb_r looks like res = rrd_dump_cb_r(filename, opt_header, rrd_dump_opt_cb_fileout, (void *)out_file); where the last parameter specifies the file handle rrd_dump_opt_cb_fileout should write to. There's no specific condition for the callback to detect when it is called for the first time, nor for the last time. If you require this for initialization and cleanup you should do those tasks before and after calling rrd_dump_cr_r respectively. UTILITY FUNCTIONS
rrd_random() Generates random numbers just like random(). This further ensures that the random number generator is seeded exactly once per process. rrd_add_ptr(void ***dest, size_t *dest_size, void *src) Dynamically resize the array pointed to by "dest". "dest_size" is a pointer to the current size of "dest". Upon successful realloc(), the "dest_size" is incremented by 1 and the "src" pointer is stored at the end of the new "dest". Returns 1 on success, 0 on failure. type **arr = NULL; type *elem = "whatever"; size_t arr_size = 0; if (!rrd_add_ptr(&arr, &arr_size, elem)) handle_failure(); rrd_add_strdup(char ***dest, size_t *dest_size, char *src) Like "rrd_add_ptr", except adds a "strdup" of the source string. char **arr = NULL; size_t arr_size = NULL; char *str = "example text"; if (!rrd_add_strdup(&arr, &arr_size, str)) handle_failure(); rrd_free_ptrs(void ***src, size_t *cnt) Free an array of pointers allocated by "rrd_add_ptr" or "rrd_add_strdup". Also frees the array pointer itself. On return, the source pointer will be NULL and the count will be zero. /* created as above */ rrd_free_ptrs(&arr, &arr_size); /* here, arr == NULL && arr_size == 0 */ rrd_mkdir_p(const char *pathname, mode_t mode) Create the directory named "pathname" including all of its parent directories (similar to "mkdir -p" on the command line - see mkdir(1) for more information). The argument "mode" specifies the permissions to use. It is modified by the process's "umask". See mkdir(2) for more details. The function returns 0 on success, a negative value else. In case of an error, "errno" is set accordingly. Aside from the errors documented in mkdir(2), the function may fail with the following errors: EINVAL "pathname" is "NULL" or the empty string. ENOMEM Insufficient memory was available. any error returned by stat(2) In contrast to mkdir(2), the function does not fail if "pathname" already exists and is a directory. AUTHOR
RRD Contributors <rrd-developers@lists.oetiker.ch> 1.4.3 2009-11-15 librrd(3)
All times are GMT -4. The time now is 04:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy