Truncate all characters and numbers in string - using perl

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Truncate all characters and numbers in string - using perl
# 1  
Old 09-06-2011
Error Truncate all characters and numbers in string - using perl


I have an data from file where it has
20110904 234516  <<hdd-10#console|0c.57,passed,5,28,READ,0,20822392,8,5,4,0,40,0,-1,0,29909,25000,835,3.3,0,0,0,0,implied,0,0,2011/9/5-2:3:17,2011/9/5-2:3:47,X292_0F15,TAP  ,NQ09,J40LTG\r\r\n

I want to remove characters till #console| i.e want to remove
20110904 234516  <<hdd-10#console|

So that result must be
0c.57,passed,5,28,READ,0,20822392,8,5,4,0,40,0,-1,0,29909,25000,835,3.3,0,0,0,0,implied,0,0,2011/9/5-2:3:17,2011/9/5-2:3:47,X292_0F15,TAP   ,NQ09,J40LTG

it must truncate last characters \r\r\n also.

need regx in perl..

# 2  
Old 09-06-2011
perl -nle 'print $2 if /(.+?)\|(.*)/' filename

This User Gave Thanks to pravin27 For This Post:
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 truncate a string to x number characters?

Hello: I have a large file which contains lines like the following: 1/t123ab, &Xx:1:1234:12345:123456@ABCDEFG... at -$100.00% /t is a tab, spaces are as indicated the string "&Xx:1:1234:12345:123456$ABCDEFG..." has a slightly variable number of numbers and letters, but it always starts... (9 Replies)
Discussion started by: Tectona
9 Replies

2. Shell Programming and Scripting

truncate string to integer or decimal

From strings stored in variables, I need to isolate and use the first numerical value contained within them. I will need to know how to produce an integer as well as a floating point decimal. It needs to work on any string regardless of what types of characters (if any) are preceding or following... (3 Replies)
Discussion started by: bradlecat
3 Replies

3. Shell Programming and Scripting

Truncate string variable

Hi, I want to truncate a string variable, returned in the script. In perl I used the below and it worked. BRNo=BR12345 $BR = substr($BRNo, 2, 7) How can I do it in sh. Thanks ! (8 Replies)
Discussion started by: script2010
8 Replies

4. Shell Programming and Scripting

Truncate file name to 40 characters

Hello all. I would like to make a script (or two shell scripts) that will do the following. I need the maximum file name and directory name to be 38 characters long. As well, if shortening the file name ends up making all of the files in that directory have the same name, then I would like... (9 Replies)
Discussion started by: marcozd
9 Replies

5. Shell Programming and Scripting

Want the substring of a string with special characters using perl

Hi, I am trying to separate the directory from the filename using the substring and it does not like it. $Complete_name="C:\ABCD\Reports_Split\090308.1630" I want $File_Name as 090308.1630 I tried using Substring function and it does not like slashes in the complete_name. Any... (5 Replies)
Discussion started by: sushma0907
5 Replies

6. Shell Programming and Scripting

truncate a string from the end

hi, guys. I have a question. If I have a long string like this: 8.0K:/home/test/brownj How can I get a substring which starts from the last slash to the end of the string, so in this case, it will be brownj Thank you very much for you time in advance -Keyang (4 Replies)
Discussion started by: daikeyang
4 Replies

7. Shell Programming and Scripting

Truncate the content within alt attribute to first 250 characters.

I have a xml file which contains image tag as follows: <image><img src="wstc_0007_0007_0_img0001.jpg" width="351" height="450" alt="This is the cover page. Brazil &#x2022; Japan &#x2022; Korea &#x2022; Mexico &#x2022; Singapore &#x2022; Spain" type="photograph" orient="portrait"/></image> ... (5 Replies)
Discussion started by: parshant_bvcoe
5 Replies

8. UNIX for Dummies Questions & Answers

Truncate last <n> characters from a file

I am trying to concatenate 2 files, but before concatenation, I would like to strip off the final character from the first file. The final character is a form feed (ascii 012 / hex 0C) and there will be an unknown number of these characters in the file. It is only the very last one which I want... (1 Reply)
Discussion started by: Gwailo88
1 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then compare numbers!

Hi All, I have a file that I need to be able to find a pattern match on a line, take the number on that line check if its >0.9 or <0.1 and if this is true write the line to output.out file. An example of 4 lines in my file is: 1. driver.I177.I11.net010 1.48622200477273e-05 2.... (2 Replies)
Discussion started by: Crypto
2 Replies

10. UNIX for Advanced & Expert Users

perl: string comparison as numbers

$name = 'Mark'; $goodguy = 'Tody'; if ($name == $goodguy) { print "Hello, Sir.\n"; } else { print "Begone, evil peon!\n"; } The output is Hello, Sir...... Even if the Mark is made to MarkSpencer.....then also it shows as Hello, Sir.... Can any one explain the... (7 Replies)
Discussion started by: bishweshwar
7 Replies
Login or Register to Ask a Question