![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| removing leading zero | risshanth | UNIX for Dummies Questions & Answers | 0 | 02-08-2008 06:51 AM |
| append zero's in the begining | ganapati | UNIX for Dummies Questions & Answers | 3 | 01-17-2008 12:41 PM |
| Aleri is Not the Leading CEP Vendor, Sorry. | iBot | Complex Event Processing RSS News | 0 | 12-07-2007 06:20 AM |
| Leading zeros | wtofu | Shell Programming and Scripting | 1 | 09-16-2006 02:52 PM |
| Leading and Trailing Spaces | sleepster | Shell Programming and Scripting | 7 | 10-29-2003 11:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Leading Zero's
I'm trying to write a script that compare's some numeric values in a file, but in one of the files the value always has leading zero's. For example -
temp_8719_LM344_20031216091826: printera : 552 : 276 : 552 : 276 temp_8719_LM344_20031216091826: printera : 000552 :000276 : 000552 : 000276 How or what coding can I use to ignore these leading zeros? |
|
|||||
|
In awk...
awk '{gsub(": *0*",": ")};1' $InFile > $OutFile In sed... sed 's/: *0*/: /g' $InFile > $OutFile However, this conversion is not necessary if you are comparing numbers in a script when you use "-eq" and "-ne" instead of "=" and "!=" |
|
|||||
|
However, this conversion is not necessary if you are comparing numbers in a script when you use "-eq" and "-ne" instead of "=" and "!="
Ygor brings up a good point that many people either forget or ignore. Integer comparison uses -eq, -lt, -gt, -ge etc while string comparison is done using = != |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|