![]() |
|
|
|
Registered
Join Date: Dec 2005
Posts: 1,284
|
Bash script help
HI, i have a file with various numbers, but the file contains some numbers with leading zeros
01 02 03 04 how do i strip the leading zeros from the contents of the file????? having brain fart compounded by beer.
__________________
Have you ever felt suffocated while watching the Oxygen Channel? People with excuses fail. As soon as I OK my actions with an excuse, I cease bettering myself. 88 Carrera |
||
![]() |
|
Registered
|
If you are trying to get rid of the first character, then you could use 'cut'.
cut -b 2 file_one > file_two Else, you have to look at 'sed'.
__________________
Make sure to check out my balls in the Pelican Parts Catalog! 917 inspired shift knobs. '84 Targa - Arena Red - AX #104 '07 Toyota Camry Hybrid - Yes, I'm that guy... '01 Toyota Corolla - Urban Camouflage - SOLD |
||
![]() |
|
Too big to fail
|
cat file | sed -e s/^0*//g > file.new
__________________
"You go to the track with the Porsche you have, not the Porsche you wish you had." '03 E46 M3 '57 356A Various VWs |
||
![]() |
|
Gon fix it with me hammer
|
what are you using to bash with? sledgehammer or baseball bat?
__________________
Stijn Vandamme EX911STARGA73EX92477EX94484EX944S8890MPHPINBALLMACHINEAKAEX987C2007 BIMDIESELBMW116D2019 |
||
![]() |
|
Registered
Join Date: Mar 2003
Posts: 10,355
|
you could use the -i arg to sed and not have to cat it or redirect to a new file
sed -i s/^0*//g filename Or you could use expr and add the numbers to 0, which will drop all insignificant digits for i in `cat file` do expr $i + 0 >> newfile done Although thats kinda sloppy... but depending on how the file is structured, may be required.
__________________
“IN MY EXPERIENCE, SUSAN, WITHIN THEIR HEADS TOO MANY HUMANS SPEND A LOT OF TIME IN THE MIDDLE OF WARS THAT HAPPENED CENTURIES AGO.” |
||
![]() |
|
Registered
Join Date: Dec 2005
Posts: 1,284
|
thanks guys...
![]()
__________________
Have you ever felt suffocated while watching the Oxygen Channel? People with excuses fail. As soon as I OK my actions with an excuse, I cease bettering myself. 88 Carrera |
||
![]() |
|
![]() |