Pelican Parts Forums

Pelican Parts Forums (http://forums.pelicanparts.com/)
-   Off Topic Discussions (http://forums.pelicanparts.com/off-topic-discussions/)
-   -   Bash script help (http://forums.pelicanparts.com/off-topic-discussions/424372-bash-script-help.html)

pmajka 08-09-2008 07:07 PM

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.

slodave 08-09-2008 09:00 PM

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'.

widebody911 08-09-2008 09:14 PM

cat file | sed -e s/^0*//g > file.new

svandamme 08-10-2008 02:08 AM

what are you using to bash with? sledgehammer or baseball bat?

id10t 08-10-2008 05:39 AM

Quote:

Originally Posted by widebody911 (Post 4111216)
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.

pmajka 08-10-2008 06:21 AM

thanks guys... :)


All times are GMT -8. The time now is 02: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


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