Solved

UNIX SCRIPT HELP

Posted on 2012-04-12
3
254 Views
Last Modified: 2012-04-12
I have a file which has the following data
022D0
00709
00701
006F9
006F1
022CF
022CE
022D1
00846
0068A

How do I write a script do that the 0's are removed from each row, So when I input the above file the output should looks like

22D0
709
701
6F9
6F1
22CF
22CE
22D1
846
68A
0
Comment
Question by:mnis2008
3 Comments
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
ID: 37839768
Well there are several ways.  Rather than re-inventing the wheel take a look at this site for many of them:  

http://unstableme.blogspot.com/2010/04/remove-leading-zero-from-line-awk-sed.html

My personal favorite is using vi

:1,$ s/^[0]*//


That is what I am used to.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 37839791
sed 's/^0\{1,\}//' lunids
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 37840163
As a command:

sed "s/^0*//" file

Or in a script:

sed "s/^0*//" $1
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question