Raynon
September 16, 2007, 9:29am
1
Hi All,
I would like to trim the following input.
My condition is as long as there's a zero on the left of the number, remove the zeros. Can anybody help me by using sed or awk ?
Eg:
0011 => change to => 11
0333 => change to => 333
4444 => No change => 4444
echo "0011" | sed "s/^0*//"
echo 0011 | awk '{print $0+0}'
zsh 4.3.4% printf "%d\n" "0011" "0333" "4444"
11
333
4444
code:
cat filename | sed 's/^0*//'
Raynon
September 25, 2007, 8:54am
8
Hi all,
How about doing the reverse way?
For EG,
I need a 2 character numeric term all the time.
7 ->change to -> 07
8 -> change to -> 08
10 -> No change -> 10
$ printf "%02d\n" 7 8 10
07
08
10
This is a great command.
What if the text string contains alphanumeric characters before it?
I was trying to get this to work, but was unsuccessful.
Please post a sample from your input and an example of the desired output.
echo "myfile0011" | sed "s/^0*//"
or
echo "0011mile" | sed "s/^0*//"
shoud be myfile11 or 11myfile
I'm not sure, do you mean this?
% printf "%s\n" 0011myfile myfile00220 my003303file|sed "s 00*\([1-9]*\) \1 "
11myfile
myfile220
my3303file
%