Perl Pattern Matching Question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Perl Pattern Matching Question
# 1  
Old 10-30-2012
Perl Pattern Matching Question

Hi all,

I have a pattern matching problem in which i'm not sure how to attack.

Here is my problem:
I have a list of strings that appear in the following format:
String: LE_(1234 ABC)^2^ABC^DEFG

What i need to do is replace all the characters after the first ^ with blank. So the output would look as the following:
LE_(1234 ABC)

Another part of the problem is that the first part of the string will change in length. i.e. LE_(1234 ABC) will not always be 13 characters long. Also ^2^ABC^DEFG will not always be 11 characters longs.

The only thing that is constant is the ^. And I need to remove all characters after that.

I would like to do this in Perl.

Thanks in advance.
# 2  
Old 10-30-2012
If you want to remove all characters (including new-lines) after the first circumflex (^) including circumflex itself:
Code:
$your_var =~ s/\^.*//s;

and if you want to start from the first circumflex and end at the first new-line (excluding the new-line) after that:
Code:
$your_var =~ s/\^.*//;


Last edited by elixir_sinari; 10-30-2012 at 10:54 AM..
# 3  
Old 10-30-2012
Thanks elixir!!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pattern matching question

Hi guys I have the following case statement in my script: case $pn.$db in *?.fcp?(db)) set f ${pn} cp ;; *?.oxa?(oxa) ) set oxa $pn ;; esac Can somebody help me to understand how to interpret *?.fcp?(db)) or *?.oxa?(oxa) ? I cannot figure out how in this case pattern maching... (5 Replies)
Discussion started by: aoussenko
5 Replies

2. Shell Programming and Scripting

pattern matching question

Hi Guys I am trying to check if the pattern "# sign followed by one or several tabs till the end of the line" exists in my file. I am using the following query: $ cat myfile | nawk '{if(/^#\t*$/) print "T"}' Unfortunately it does not return the desired output since I know for sure that the line... (4 Replies)
Discussion started by: aoussenko
4 Replies

3. Shell Programming and Scripting

Pattern matching question

Hi Guys, I am trying to setup a check for the string using an "if" statement. The valid entry is only the one which contain Numbers and Capital Alpha-Numeric characters, for example: BA6F, BA6E, BB21 etc... I am using the following "if" constract to check the input, but it fails allowing Small... (3 Replies)
Discussion started by: aoussenko
3 Replies

4. Shell Programming and Scripting

pattern matching question

Hi guys, I have a file in the following format: 4222 323K 323L D222 494 8134 A023 A024 49 812A 9871 9872 492 A961 A962 A963 491 0B77 0B78 0B79 495 0B7A 0B7B 0B7C 4949 WER9 444L 999O I need to grep the line... (5 Replies)
Discussion started by: aoussenko
5 Replies

5. Shell Programming and Scripting

Pattern matching question

Hi, I am writing a simple log parsing system and have a question on pattern matching. It is simply grep -v -f patterns.re /var/log/all.log Now, I have the following in my logs Apr 16 07:33:17 ad-font-dc1 EvntSLog: AD-FONT-DC1/NTDS ISAM (700) - "NTDS (384) NTDSA: Online defragmentation... (5 Replies)
Discussion started by: wpfontenot
5 Replies

6. Shell Programming and Scripting

Pattern matching question

Hi guys, I have the following expression : typeset EXBYTEC_CHK=`egrep ^"+${PNUM}" /bb/data/firmexbytes.dta` can anybody please explain to me what ^"+${PNUM}" stands for in egrep statement? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Shell Programming and Scripting

Perl pattern matching!!

Hi experts, I have many occurances of the following headers in a file. I need to grep for the word changed/inserted in the header, calculate the difference between the two numbers and list the count incrementally. Headers in a file look like this: ------------------- ---------------------... (6 Replies)
Discussion started by: nmattam
6 Replies

8. Shell Programming and Scripting

Perl Pattern Matching

Hello experts, I have a file containing the following text(shortened here). File Begin ---------- < # Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 < Billboard.d3fc1302a677.imagePath=S:\\efcm_T4 --- > # Billboard.d3fc1302a677.imagePath=S:\\efcm_Cassini >... (2 Replies)
Discussion started by: nmattam
2 Replies

9. Shell Programming and Scripting

perl pattern matching

hi i am trying to get digits inside brackes from file , whose structure is defined below CREATE TABLE TELM (SOC_NO CHAR (3) NOT NULL, TXN_AMOUNT NUMBER (17,3) SIGN_ON_TIME CHAR (8) TELLER_APP_LIMIT NUMBER (17,3) FIL01 ... (2 Replies)
Discussion started by: zedex
2 Replies

10. Shell Programming and Scripting

pattern matching + perl question

i can only find the first occurance of a pattern how do i set it to loop untill all occurances have changed. #! /usr/bin/perl use POSIX; open (DFH_FILE, "./dfh") or die "Can not read file ($!)"; foreach (<DFH_FILE>) { if ($_ !~ /^#|^$/) { chomp; ... (1 Reply)
Discussion started by: Optimus_P
1 Replies
Login or Register to Ask a Question