Delete specific characters


 
Thread Tools Search this Thread
Operating Systems AIX Delete specific characters
# 1  
Old 04-20-2008
Error Delete specific characters

Hi every1

Well i have a list of numbers e.g

12304
13450
01234
00123
14567

what i want is a command to check if the number is starting from 0 and then delete the 0 without doing anything else!!!!
any help wud b appreciated!!!!!!!!Smilie
# 2  
Old 04-20-2008
Quote:
Originally Posted by masquerer

... to check if the number is starting from 0 and then delete the 0 without doing anything else!!!!

Removing only the first 0:

Code:
awk '{sub(/^0/,"")}1' list

# 3  
Old 04-21-2008
I presume you want to delete all the leading zeroes, not only the first one, right? This the solution in sed:

Code:
sed 's/^00*//' /path/to/sourcefile > /path/to/resultfile

It should be said that both the awk- and the sed-solution are easily changed to achieve the respective other conceivable goal.

I hope this helps.

bakunin
# 4  
Old 04-21-2008
using Perl:
Code:
perl -pi -e 's/^0+//' filename

# 5  
Old 04-21-2008
Another one:

Code:
awk '{print int($0)}' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Delete and retain some characters

Ive been trying to google and tried sed and awk. BUt still getting no exact formula. I would like to know how to parse this at: From: Compute Machin Appliance 3.2.9.10000 123456 To: Compute Machin Appliance 3.2.9.123456 (5 Replies)
Discussion started by: kenshinhimura
5 Replies

3. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

4. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

5. Shell Programming and Scripting

How delete characters of specific line with sed?

Hi, I have a text file with some lines like this: /MEDIA/DISK1/23568742.MOV /MEDIA/DISK1/87456321.AVI /MEDIA/DISK2/PART1/45753131.AVI /IMPORT/44452.WAV ... I want to remove the last 12 characters in each line that it ends "AVI". Should look like this: /MEDIA/DISK1/23568742.MOV... (12 Replies)
Discussion started by: inaki
12 Replies

6. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

7. Shell Programming and Scripting

delete first 2 characters for each line, please help

hi, ./R1_970330_210505.sard ./R1_970403_223412.sard ./R1_970626_115235.sard ./R1_970626_214344.sard ./R1_970716_234214.sard ... ... ... for these strings, i wanna remove the ./ for each line how can i do that? i know it could possibly be done by sed, but i really have not idea how... (4 Replies)
Discussion started by: sunnydanniel
4 Replies

8. Shell Programming and Scripting

need to Delete first 10 characters of a file name

Hello Everyone, I need help in deleting first 10 characters from the filename in a directory eg: 1234567890samplefile1.txt 1234567890samplefile2.txt and so on.. need to get the output as samplefile1.txt Thanks in Advance!!!! (8 Replies)
Discussion started by: Olivia
8 Replies

9. Shell Programming and Scripting

How to delete characters using a file

Hi All, I have a configuration file (file.cfg) in which data will be like this ; , _ + a to z A to Z Now i have to read a textfile (file.txt) and i need to check whether there is any other character present in text file that is not existing in (file.cfg). If other characters are present... (4 Replies)
Discussion started by: krishna_gnv
4 Replies

10. Shell Programming and Scripting

tell me how many specific characters there are?

i'm trying to get the user to enter a character, then the script should search for how many of that character exists in the file. I have the following code, but it doesn't work properly and it shows the wrong amount (i don't think im supposed to use grep). For example, I want it to say, "There are... (7 Replies)
Discussion started by: kev269
7 Replies
Login or Register to Ask a Question