echo + bc + format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo + bc + format
# 1  
Old 06-03-2009
echo + bc + format

Hi,

I was trying to define a variable as a result of an operation,

b=` echo $a+1 | bc -l`

with a specific format (5 digits integer completing with zeros, 00025, for example)

c=` printf "%05d\n" b `

Does anyone how can it be done in one step in bash shell to get the formatted variable c? Thanks in advanced
# 2  
Old 06-03-2009
With recent versions of bash:

Code:
$ unset c
$ printf -vc %05d $((5*5))
$ echo $c
00025

With older versions:

Code:
$ unset c
$ c=$(printf %05d $((5*5)))
$ echo $c
00025

# 3  
Old 06-03-2009
Thanks a lot! the second way works perfectly!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Drive Offline on echo | format

Hi just want to ask if anyone has encounter this error? bash-3.2# echo | format Searching for disks...Mar 28 14:03:31 server1 scsi: WARNING: /pci@340/pci@1/pci@0/pci@7/SUNW,qlc@0,1/fp@0,0/ssd@w5006016408607763,0 (ssd3): Mar 28 14:03:31 server1 drive offline Mar 28 14:03:31 server1 scsi:... (1 Reply)
Discussion started by: gob23g
1 Replies

2. Solaris

Grant unprivileged user rights to see the output of echo|format but not modify disks

anyone have any idea how do to this with auth_attr? I suspect if I grant him solaris.device.:RO::Device Allocation::help=DevAllocHeader.html that will work but I'm unsure. Just looking for a second opinion. (10 Replies)
Discussion started by: os2mac
10 Replies

3. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Shell Programming and Scripting

Column format using echo in aix

Hi Friends, I have the following values in echo "$csi_tas_id" echo "$platform" echo "$region" I want to display these values as shown below: CSI_TAS_ID | PLATFORM | REGION 123 | UNIX | SG 231 | AIX ... (1 Reply)
Discussion started by: dbashyam
1 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. UNIX for Dummies Questions & Answers

Format output from "echo" command

Hi, I have written a BASH shell script that contains a lot of "echo" commands to notify the user about what's going on. The script generates a log file that contains a copy of what is seen in the terminal. The echo statements are generally verbose, and thus extend out for quite a ways on one... (2 Replies)
Discussion started by: msb65
2 Replies

7. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

8. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

9. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

10. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies
Login or Register to Ask a Question