Remove 3rd character from the end of a random-length string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove 3rd character from the end of a random-length string
# 1  
Old 05-19-2012
Remove 3rd character from the end of a random-length string

Hi,

I hope someone can share there scripting fu on my problem,

I would like to delete the 3rd character from a random length of string starting from the end

Example
Quote:
123456789
124sdf546dfg
14we657rh
3241drfsef435
Output
Quote:
12345789
124sdf56dfg
14we67rh
3241drfse435
Hope you can help me..

Thanks in advance..
# 2  
Old 05-19-2012
Code:
perl -pe 's/.(.{3})$/\1/' file

# 3  
Old 05-19-2012
Same script in sed:
Code:
sed 's/.\(...\)$/\1' file

# 4  
Old 05-19-2012
Thanks much it helps..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print the string between 3rd and 4th backslashs to end of line

im trying to get awk to print the string between 3rd and 4th backslashs to end of line test could be any word this http://example.com/test/ >to this http://example.com/test/ > testalso the other way round insert string at end of line... (13 Replies)
Discussion started by: bob123
13 Replies

2. Shell Programming and Scripting

Add string based on character length

Good day, I am a newbie here and thanks for accepting me I have a task to modify input data where my input data looks like 123|34567|CHINE 1|23|INDIA 34512|21|USA 104|901|INDIASee that my input has two columns with different character length but max length is 5 and minimum length is 0 which... (1 Reply)
Discussion started by: fastlearner
1 Replies

3. Shell Programming and Scripting

Generating a Random String of 'n' length

Hi, How can I generate a string of random characters (alpha+numeric) of a particular length ? For e.g. for n=5, output = 'kasjf' n=10, output = 'hedbcd902k' Also, please let me know if random (valid) dates could also be generated. Thanks (7 Replies)
Discussion started by: rishigc
7 Replies

4. Shell Programming and Scripting

How to Remove comma as last character in end of last line of file?

how to Remove comma as last charector in end of last line of file: example: input file --------------- aaaaaa, bbbbbb, cccc, 12345, ____________ output file : ----------- aaaaaa, bbbbbb, (6 Replies)
Discussion started by: RahulJoshi
6 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

How to remove new line character at end of file.

I need to remove new line character from end of file. Suppose here are content. a|b|c|d|r a|b|c|d|r a|b|c|d|r <new line> that means file contains 4 lines but data is there in 3 lines. so I want that only 3 lines should be there in file. Please help (20 Replies)
Discussion started by: varun940
20 Replies

7. Shell Programming and Scripting

Remove 3rd and onwards occurances of a character

I have a file with "@" in every line fdgfgddfg@sfsdfdsf@dfdfd@@vfdfsdfd@ sfsdfs@sdfd@gfhfgh@@ddffg@sdf@ srfgtfsdfs@sdfertrd@eergfhfgh@@ddffg@sdf@ wttrtrt@sdfd@sdfdf@@sdfdfds@@@ I need to remove all the fourth and onwards occurences of "@". so my final o/p would be fdgfgddfg@sfsdfdsf@dfdfd@... (7 Replies)
Discussion started by: Shivdatta
7 Replies

8. Shell Programming and Scripting

Parsing 286 length Character string

Hi Friends, I have .txt file which has 13000 records. Each record is 278 character long. I am using below code to extract the string and it takes almost 10 minutes. Any suggestion please. cat filename.txt|while read line do f1=`echo $line|awk '{print substr($1,1,9)}'` f2=`echo... (6 Replies)
Discussion started by: ppat7046
6 Replies

9. Shell Programming and Scripting

How to remove a newline character at the end of filename

Hi All, I have named a file with current date,time and year as follows: month=`date | awk '{print $2}'` date=`date | awk '{print $3}'` year=`date | awk '{print $6}'` time=`date +%Hh_%Mm_%Ss'` filename="test_"$month"_"$date"_"$year"_"$time".txt" > $filename The file is created with a... (2 Replies)
Discussion started by: amio
2 Replies

10. Shell Programming and Scripting

Remove box like special character from end of string

Hi All, How to remove a box like special character which appears at the end of a string/line/record. I have no clue what this box like special character is. It is transparent square like box. This appears in a .DAT file at the end of header. I'm to compare a value in header with a parameter.... (16 Replies)
Discussion started by: Qwerty123
16 Replies
Login or Register to Ask a Question