Pelican Parts
Parts Catalog Accessories Catalog How To Articles Tech Forums
Call Pelican Parts at 888-280-7799
Shopping Cart Cart | Project List | Order Status | Help



Go Back   Pelican Parts Forums > Miscellaneous and Off Topic Forums > Off Topic Discussions


Reply
 
LinkBack Thread Tools Rate Thread
Author
Thread Post New Thread    Reply
Registered
 
pmajka's Avatar
 
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
Old 08-09-2008, 06:07 PM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #1 (permalink)
Registered
 
slodave's Avatar
 
Join Date: Sep 2005
Location: Encino Man
Posts: 22,394
Garage
Send a message via Skype™ to slodave
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
Old 08-09-2008, 08:00 PM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #2 (permalink)
Too big to fail
 
widebody911's Avatar
 
Join Date: Jan 2002
Location: Carmichael, CA
Posts: 33,894
Garage
Send a message via AIM to widebody911 Send a message via Yahoo to widebody911
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
Old 08-09-2008, 08:14 PM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #3 (permalink)
Gon fix it with me hammer
 
svandamme's Avatar
 
Join Date: Sep 2003
Location: In Flanders Fields where the poppies blow
Posts: 23,537
Garage
what are you using to bash with? sledgehammer or baseball bat?
__________________
Stijn Vandamme
EX911STARGA73EX92477EX94484EX944S8890MPHPINBALLMACHINEAKAEX987C2007
BIMDIESELBMW116D2019
Old 08-10-2008, 01:08 AM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #4 (permalink)
Registered
 
id10t's Avatar
 
Join Date: Mar 2003
Posts: 10,355
Quote:
Originally Posted by widebody911 View Post
cat file | sed -e s/^0*//g > file.new
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.”
Old 08-10-2008, 04:39 AM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #5 (permalink)
Registered
 
pmajka's Avatar
 
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
Old 08-10-2008, 05:21 AM
  Pelican Parts Catalog | Tech Articles | Promos & Specials    Reply With Quote #6 (permalink)
 
Reply


 


All times are GMT -8. The time now is 08:04 PM.


 
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2025 Pelican Parts, LLC - Posts may be archived for display on the Pelican Parts Website -    DMCA Registered Agent Contact Page
 

DTO Garage Plus vBulletin Plugins by Drive Thru Online, Inc.