matching regexp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching regexp
# 1  
Old 06-18-2010
matching regexp

Hi,

maybe it is stupid question, but is it possible to match expression like this ? :

... // ... ( there is "//" somewhere on the line and on the end of the line there ISN'T "*/" )

I've tried something like : (in SED)

sed 's/\/\/[^*/]'

but I need "*/" not to be on the end of the line ... I know there is a special char for this $, but how to use it there...

Thanks for any answers...
# 2  
Old 06-18-2010
Quote:
Originally Posted by kolage
...
... // ... ( there is "//" somewhere on the line and on the end of the line there ISN'T "*/" )

I've tried something like : (in SED)

sed 's/\/\/[^*/]'

but I need "*/" not to be on the end of the line ... ...
Something like this ?

Code:
$
$
$ cat f6
line 1 - the quick brown fox jumps over the lazy dog
line 2 - the quick brown // fox jumps over the lazy dog
line 3 - the quick brown // fox jumps over the lazy dog */
line 4 - the quick//brown fox jumps over the lazy dog
line 5 - the quick//brown fox jumps over the lazy dog*/
line 6 - the quick // brown fox */ jumps over the lazy dog
$
$
$ sed -n '/\/\/.*[^*\/]$/p' f6
line 2 - the quick brown // fox jumps over the lazy dog
line 4 - the quick//brown fox jumps over the lazy dog
line 6 - the quick // brown fox */ jumps over the lazy dog
$
$ # or using Perl
$ perl -lne '/\/\/.*[^*\/]$/ and print' f6
line 2 - the quick brown // fox jumps over the lazy dog
line 4 - the quick//brown fox jumps over the lazy dog
line 6 - the quick // brown fox */ jumps over the lazy dog
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 3  
Old 06-18-2010
thanks a lot it is exactly what I wanted to know... Smilie but I am little bit surprised that I got answer right from you, because yesterday I saw Fight club and today you are here, answering me ... so I am little bit scared that I wrote that answer by myself Smilie .
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 combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

3. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

4. Shell Programming and Scripting

perl regexp: matching the parent xml tag

Hi folks. I would like to remove the full parent (outer) xml tag from a file given a matching child (inner) tag, in a bash shell. To be more specific, this is what I have so far: $ cat myFile.xml <Sometag></Sometag> <Outer> <Inner>1</Inner> </Outer> <Outer> <stuff>alot</stuff> ... (3 Replies)
Discussion started by: BatManWSL
3 Replies

5. Shell Programming and Scripting

perl regexp matching

Hello, I cannot see what's wrong in my code. When I run code below, it just print an empty string. my $test = "SWER~~ERTGSDFGTHAS_RTAWGA_DFAS.x4-234253454.in"; if ($test = ~ m/\~{1,2}.*4/) { print "$1\n"; } else { print "No match...\n"; } Anyone know what I'm doing wrong? ... (4 Replies)
Discussion started by: urandom
4 Replies

6. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

7. Shell Programming and Scripting

regexp help

I'd like to know if there is a catchall line for renaming the following patterns: s01e03 -> 01x03 s4e9 -> 04x09 s10e08 ->10x08 and possibly even: 318 -> 03x18 1002 ->10x02 if its the first 3 or first digit number in the string. thanks! (0 Replies)
Discussion started by: TinCanFury
0 Replies

8. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies

9. UNIX for Advanced & Expert Users

regexp

Hi guys, does anyone know how to test for a regular expression - i want to include it in a script to make sure the variable is a regexp cheers (1 Reply)
Discussion started by: penfold
1 Replies

10. UNIX for Dummies Questions & Answers

GnuWin32 sed 4.1.4 regexp matching

I am using GnuWin32 sed and am having trouble with the regexp - i.e., they don't behave the same way as in UNIX (POSIX and and all that). I have a stream of data, e.g.: 11111'222?'22'33?'333'44444'55555' I want to insert a \n after those apostrophes that are *not* preceded by a ?. ... (2 Replies)
Discussion started by: Simerian
2 Replies
Login or Register to Ask a Question