Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete zeros in a row

Status
Not open for further replies.

tonivm

Technical User
Mar 2, 2006
64
ES
hi everybody:
Could anybody tell me how I can from a row which is:

00
01
02
03
04
05
06
07
08
09
10
11
......

delete the first zero and then I will have:
1
2
3
4
5
6
7
8
9
10
11
........

Thanks in advance and cheers. :)
 
sed 's/^0//' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try this,

sed '2,10 s/0/ /' input_file | awk '{if($1 !~/^0/) print $1 }'> output_file

input_file=contains a zeros
output_file=without zeros

tested with awk.

Regards
 
Hi

Nice try gargamel100, but both [tt]sed[/tt] and [tt]awk[/tt] can solve this alone :
Code:
sed 's/^0\+//;/^$/d' /input/file

[gray]# or[/gray]

awk '$0{print $0+0}' /input/file
And to appreciate your speed optimization :
Code:
sed '1,/^[^0]/{s/^0\+//;/^$/d}' /input/file

[gray]# or[/gray]

awk 'NR==1,!/^0/{if($0)print $0+0;next}1' /input/file
Tested with GNU [tt]sed[/tt], [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Just for grins:

Code:
!/bin/ksh

typeset -i x

while read x
do
echo $x
done < in.file > out.file
 
Hi

Sorry, I found no suitable grin emoticon in Tek-Tips' collection.
Code:
[red]#[/red]!/bin/ksh

typeset -i x

while read x
do
[red]test $x -gt 0 &&[/red] echo $x
done < in.file > out.file


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top