Script to remove first character if it is zero


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to remove first character if it is zero
# 1  
Old 11-18-2009
Script to remove first character if it is zero

Hi All,
I have a input like this.
01
i want the output like this.
1
But if the input file is like
11 i should not do anything.
Can anyone please help to get a command to do this.

thanks,
Giri.

---------- Post updated at 02:11 AM ---------- Previous update was at 02:04 AM ----------

Friends i got the required command.

Thanks,
Girish.
# 2  
Old 11-18-2009
try:
Code:
sed 's/^0*\(.*\)/\1/' filename

# 3  
Old 11-18-2009
Code:
sed 's/^0//' infile

# 4  
Old 11-18-2009
Quote:
Originally Posted by dennis.jacob
try:
Code:
sed 's/^0*\(.*\)/\1/' filename


sorry. I overlooked the issue. This one will remove all starting 0's. Smilie
# 5  
Old 11-18-2009
Code:
input="01"
case "$input" in
  0*) echo ${input/#0/};;
esac

# 6  
Old 11-18-2009
All leading zeroes :
Code:
sed 's/^0*//' infile



---------- Post updated at 10:10 ---------- Previous update was at 09:54 ----------

Quote:
Originally Posted by ghostdog74
Code:
input="01"
case "$input" in
  0*) echo ${input/#0/};;
esac

Code:
input="01"
echo ${input#0}


Last edited by Scrutinizer; 11-18-2009 at 05:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

Shell script remove bad character

I was curious to know how to write into my shell script to remove a character. The character I want to remove is  within a .html file. (18 Replies)
Discussion started by: graphicsman
18 Replies

3. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

4. Linux

Linux script to remove a character in a file based on position.

Greetings, We have a requirement where we need to loop in a fixed width file in linux and remove a character based on a position for every record. It would highly appreciate if someone can help to automate this. Appreciate your time and help! Regards (3 Replies)
Discussion started by: mailme0205
3 Replies

5. Shell Programming and Scripting

remove the first and last character of a string

How can i remove the first and last character of strings like below: "^^^613*" "admt130" "^^^613*" "123456" "adg8484" "DQitYV09dh1C" Means i wanna remove the quotes(""). Please help (17 Replies)
Discussion started by: proactiveaditya
17 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

7. Shell Programming and Scripting

shell script to remove the last character(.) of a string

hi I have a list of words in a text file. these words are appended by "." at their end. They look something like this. word1. word2. word3. word4. word5. I need to remove the last character "." from all the words. The output must look something like this. word1 word2 word3... (7 Replies)
Discussion started by: ss3944
7 Replies

8. UNIX for Dummies Questions & Answers

How to remove \ character

Dear Members, I have a file which is a single line file. It has "\" character and i need to replace this character with a new line character. How can we do this? I tried with sed but it did not work. sed 's//"\n"/g' t1 > t2Thanks Sandeep (3 Replies)
Discussion started by: sandeep_1105
3 Replies

9. Shell Programming and Scripting

Remove a ^M character

Hi, I'd like to ask for some help with the following: I've cut a couple of columns of file1 to create file2 with the following code: cur -f 1,3,8 file1 > file2 Then I need to transfer file 2 from UNIX to Windows and use it further. Unfortunatelly, for some reason the line is displayed... (4 Replies)
Discussion started by: zajtat
4 Replies

10. Shell Programming and Scripting

Script to Remove Garbage Character

Hello, Whenever I transfer files between machines, I find a garbage character (^M) being appended to the end of every line of the file. Can you suggest a script wherein I can eliminate the garbage character. I tried sed 's/^M//g' < filename > filename1 ...but it doesn't work. Also, this... (4 Replies)
Discussion started by: Eddie_The_Head
4 Replies
Login or Register to Ask a Question