Perl regex problem on strings with several occurences of one char


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Perl regex problem on strings with several occurences of one char
# 1  
Old 11-19-2014
Question Perl regex problem on strings with several occurences of one char

Hi all,

i have the following line in a record file :
Code:
retenu=non
demande=non
script=#vtbackup /path=/save/backup/demande
position=140+70

and i want to use Perl regex to have the following output
Code:
key : "retenu" value : "non"
key : "demande" value "non"
key : "script"  value : "#vtbackup /path=/save/backup/demande"
key : "position" value : "140+70"

My problem is on the line "script...." and come from the 2 occurencies of equal sign.
I used index and substr to do the job, but i would like to do it using regex

Thank You for your help
--
Pat (France)

Last edited by Fundix; 11-19-2014 at 10:15 AM.. Reason: Precisions
# 2  
Old 11-19-2014
Code:
($key, $value) = m{^(.*?)=(.*)$};

You may want to get rid of leading and trailing whitespace with:
Code:
($key, $value) = m{^\s*(.+?)\s*=\s*(.*)\s*$};

This User Gave Thanks to derekludwig For This Post:
# 3  
Old 11-19-2014
Great, THANK YOU Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line. the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex" Please help. for i in `cat servername`; do ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
Discussion started by: yash_message
4 Replies

2. Shell Programming and Scripting

Perl Regex problem

Script logs into switches on my list but nothing seems to happen. Following error: tr nope, doesn't (yet) match (?-xism:-]+ ?(?:\(config*\))? ? ?$) du SEEN: Here is code in question: @version_info = $session_obj->cmd('term length 0'); $session_obj->cmd('show int | i... (5 Replies)
Discussion started by: mrlayance
5 Replies

3. Shell Programming and Scripting

Sed: -e expression #1, char 16: unterminated address regex

I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine. ... (23 Replies)
Discussion started by: rbadveti
23 Replies

4. Shell Programming and Scripting

Remove double char occurences

I have a file with random characters where every time a char occurs twice, one occurrence must be removed. Eg. asjkdhaSSd Must become: asjkdhaSd Anybody has a SED script in mind to do it? (1 Reply)
Discussion started by: rlopes
1 Replies

5. Shell Programming and Scripting

Count the occurences of strings

I have some text files in a folder f1 with 10 columns. The first five columns of a file are shown below. aab abb 263-455 263 455 aab abb 263-455 263 455 aab abb 263-455 263 455 bbb abb 26-455 26 455 bbb abb 26-455 26 455 bbb aka 264-266 264 266 bga bga 230-232 230 ... (10 Replies)
Discussion started by: gomez
10 Replies

6. Shell Programming and Scripting

How can i delete the content between all the occurences of two strings using sed or awk command

Hi. I have to delete the content between all the occurrences of the xml tags in a single file. For example: * The tags <script>.....................</script> occurs more than once in the same file. * It follows tagging rules meaning a start tag will be followed by an end tag. Will not have... (9 Replies)
Discussion started by: satheeshkumar
9 Replies

7. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

8. Shell Programming and Scripting

Regex/sed - matching any char,space,underscore between : and /

trying to remove the portion in red: Data: mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql output to be: mds_ar/bin/uedw92wp.ksh: wkly.sql mds_ar/bin/uedw92wp.ksh: wkly.sql SED i'm trying to use: sed 's/:+\//: /g' input_file.dat >... (11 Replies)
Discussion started by: danmauer
11 Replies

9. Shell Programming and Scripting

Perl - Count occurences

I have enclosed the script. I am able to find the files that contain my search string but when I try to count the occurences within the file I get zero always. Any help on this. #!/usr/bin/perl my $find = $ARGV; my $replace = $ARGV; my $glob = $ARGV; @filelist = <*$glob>; # process each... (22 Replies)
Discussion started by: TimHortons
22 Replies

10. UNIX for Dummies Questions & Answers

Counting occurences of different strings in a file

Hi, i'd like to know if the following is possible with a shell script, and can't find the answer in the search. Suppose i have a logfile build like this: # 8 :riuyzp1028 # 38 : riuyzp1028 # 25 : riuyvzp1032 # 30 : nlkljpa0202 # 1 : nlklja0205 # 38 : riuyzp1028 # 25 :... (4 Replies)
Discussion started by: Freerider
4 Replies
Login or Register to Ask a Question