Reputation: 21
I want to remove leading Zero from first column and if all Zeros are found in first column then 1 Zero should be preserved.
00123|a
00154|b
00000|c
Output
123|a
154|b
0|c
Upvotes: 1
Views: 271
Reputation: 37464
Using awk:
$ awk '
BEGIN { FS=OFS="|" } # set field separators
{ $1+=0 } # add a zero to remove leading zeros
1' file # output
Output:
123|a
154|b
0|c
Here's one that works for integers:
$ awk '
BEGIN{ FS=OFS="|" }
{ $1=sprintf("%.0f",$1) } # %.0f will round off decimals
1' file
Output:
123|a
154|b
0|c
4295229012|0
Upvotes: 1