Feb 15, 2007 #1 tonivm Technical User Joined Mar 2, 2006 Messages 64 Location 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.
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.
Feb 15, 2007 #2 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR 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 Upvote 0 Downvote
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
Feb 15, 2007 #3 gargamel100 Technical User Joined Oct 25, 2006 Messages 31 Location CZ 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 Upvote 0 Downvote
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
Feb 15, 2007 #4 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO 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. http://rootshell.be/~feherke/ Upvote 0 Downvote
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. http://rootshell.be/~feherke/
Feb 16, 2007 #5 olded Programmer Joined Oct 27, 1998 Messages 1,065 Location US Just for grins: Code: !/bin/ksh typeset -i x while read x do echo $x done < in.file > out.file Upvote 0 Downvote
Feb 17, 2007 #6 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO 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. http://rootshell.be/~feherke/ Upvote 0 Downvote
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. http://rootshell.be/~feherke/