Trim not constant number of symbols ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trim not constant number of symbols ?
# 1  
Old 01-26-2010
Trim not constant number of symbols ?

Hello,

I need to trim zeros from left side:

#echo $var1
00023456

But number of zeros is not constant.
How do I do that ?

thanks
Vilius
# 2  
Old 01-26-2010
Code:
#!/bin/ksh
var1="0001234"
typeset -i var2=$var1
echo $var2

# 3  
Old 01-26-2010
Code:
echo "0012345" | nawk '{match($0,/^[0]*/) ; $0=substr($0,RSTART+RLENGTH)}1'

o/p:-
12345

Code:
echo "0000001234500000" | nawk '{match($0,/^[0]*/) ; $0=substr($0,RSTART+RLENGTH)}1'

o/p

1234500000

Code:
echo "000000120000345" | nawk '{match($0,/^[0]*/) ; $0=substr($0,RSTART+RLENGTH)}1'

o/p:-
120000345


SmilieSmilieSmilie
# 4  
Old 01-26-2010
Or...

Code:
$ var1=000012345
$ printf "%.0f\n" $var1
12345

# 5  
Old 01-26-2010
or more simple.

Code:
val=0000000123456
nawk -v var=$val 'BEGIN{print int(var)}'

o/p
123456

SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Debian

LM 17.3 xfce constant lagging

I'm using LM 17.3x LIVE. Have constant and sometimes, severe lagging issues. Problems started when I "upgraded" to 18.3x. I tried 5 other distros all with the same issues. Went back to 17.3 and , alas, the problem followed. Found this: sudo gedit /etc/sysctl. conf vm. swappiness = 15, but all it... (4 Replies)
Discussion started by: 69Rixter
4 Replies

2. Programming

String Constant C

I wonder string constant exists permanently or temporary. For example, printf("hello, world"); the function printf access to it is through a pointer. Does it mean storage is allocated for the string constant to exist permanently in memory? :confused: (4 Replies)
Discussion started by: kris26
4 Replies

3. Shell Programming and Scripting

Keep up constant number of parallel processes

Hi guys, I am struggling with adapting my script to increase the performance. I created a ksh script to process a lot of files in parallel. I would like to know how can I do in such a way that a constant number of processes is always up (until all is finished). What I have is (not actual... (8 Replies)
Discussion started by: lurkerro
8 Replies

4. Shell Programming and Scripting

while infinite loop_sockets constant

Hello Every one, it's requiered to create 'n' number of sockets constant for a hour time. i had my own script to create sockets using this i was able to create sockets and sendind data but using the tool i can maintain 'n' number of sockets for 5 minutes only after sockets are getting reduced to... (1 Reply)
Discussion started by: mannam srinivas
1 Replies

5. Shell Programming and Scripting

Constant mirroring

I'm not sure how to best explain what I'd like to do, so let me give an example. I used to work in a department that deals with internet security. This department had an "internal" website (only people in the building can get on it) and an "external" website (anyone in the world can get on it --... (1 Reply)
Discussion started by: sstevens
1 Replies

6. AIX

AIX Constant Rebooting

IBM has replaced all parts in the system 3 times. Had electrician check to make sure the dedicated electrical circuit was good. Made sure the server rack was grounded, but AIX keeps shutting down when everyone is on the system. Reloaded AIX on the system. If the system is left alone it will stay... (4 Replies)
Discussion started by: AIXNEWBEE
4 Replies

7. Programming

File descriptor constant

I have a requirement to close all the file descriptors from 3 to 1024 for a particular application. Right now, this is how I do it .. for ( int i = 3 ; i <= 1024; ++i ) close(i); The change I am looking at is, I want to do away with the number 1024 and replace it with a constant which... (4 Replies)
Discussion started by: vino
4 Replies
Login or Register to Ask a Question