Regex extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex extraction
# 8  
Old 06-23-2008
regex extraction

Hello fpmurphy,

It helps me lot, appreciated your assistence.
I was trying to modify my requirement, everything went fine except one confusion:

If the text file contains as follows:

./s/sherg_fyd_rur:blkabl="R23.21_BL2008_0122_1"
./h/serge_a75:rlwual="/main/r23.21=26-Mar-2008.05:00:20UTC@R11.31_BL2008_0325"
./y/serge_a75:blkabl="R23.21_BL2008_0325"
./w/sherg_proto_npiv:bkguals="R23.21_BL2008_0302 I80_11.31_LR"

Then I modified the command as follows:

"Stage 1"
sed -e 's/\(^\.\/.*\)//'

It's appearing parse error.

I wanted to replace like ./s/ and I put additional .*, but not working.
Any idea?

Thank you.

abrouf
# 9  
Old 06-23-2008
regex extraction

Little modification:
I tried as follows:

Then I modified the command as follows:

"Stage 1"
sed -e 's/\(^\.\/.*/\)//'

to replace like ./s/ or ./h/

Thank you.
abrouf
# 10  
Old 06-23-2008
regex extraction

Hello fpmurphy,

Please help! I also tried making the 6 splits. Put the additional characters s/ or h/ into another veriable, but still showing parse error and returning the out put to \3 \5.

Please help.
Thank you.
abrouf
# 11  
Old 06-23-2008
Quote:
Originally Posted by abdurrouf
Hello,

I need your help to extract text from following:

./sherg_fyd_rur:blkabl="R23.21_BL2008_0122_1"
./serge_a75:rlwual="/main/r23.21=26-Mar-2008.05:00:20UTC@R11.31_BL2008_0325"
./serge_a75:blkabl="R23.21_BL2008_0325"
./sherg_proto_npiv:bkguals="R23.21_BL2008_0302 I80_11.31_LR"


I need to extract the text starting after ./ up to : (example from last line "sherg_proto_npiv") and the date only after BL (from example last line 2008_0302).

Any help is greatly appreciated.

Thank you.

abrouf
it seems you have a standard structure,
Code:
awk 'BEGIN{
 FS="[.=@: /\"]"
}
/\.\//{
 print $3
 for ( i=2;i<=NF;i++){
  if ( $i ~ /BL/) {
    sub(/.*BL/,"",$i)
    print $i
  }
 }
} 
' file

output:
Code:
# ./test.sh
sherg_fyd_rur
2008_0122_1
serge_a75
2008_0325
serge_a75
2008_0325
sherg_proto_npiv
2008_0302

if you are not familiar with regular expression, then use less of it , until you do.
# 12  
Old 06-24-2008
regex extraction

Thank you ghostdog74,

Actually my file content is as follows:
./s/sherg_fyd_rur:blkabl="R23.21_BL2008_0122_1"
./h/serge_a75:rlwual="/main/r23.21=26-Mar-2008.05:00:20UTC@R11.31_BL2008_0325"
./y/serge_a75:blkabl="R23.21_BL2008_0325"
./w/sherg_proto_npiv:bkguals="R23.21_BL2008_0302 I80_11.31_LR"

The previous sed command works file, I wanted to replace
./s/
./h/
./y/
./w/

So I modified as
sed -e 's/\(^\.\/.*/\)//'

added .*/ to replace like s/, but this part is not working. I also put this part different pattern buffer, still no luck.

I appreciate your help.

Thank you.

abrouf
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. Shell Programming and Scripting

Sequence extraction

i want to extract specific region of interest from big file. i have only start position, end position and seq id, see my query is: I have file1 is this >GL3482.1 GAACTTGAGATCCGGGGA GCAGTGGATCTCCACCAG CGGCCAGAACTGGTGCAC CTCCAGGCCAGCCTCGTC CTGCGTGTC >GL3550.1... (14 Replies)
Discussion started by: harpreetmanku04
14 Replies

3. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

extraction

I have following input @xxxxxx@ I want to extract what's between @....@ that is : xxxx using SED command (6 Replies)
Discussion started by: xerox
6 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Extraction of Filename

HI, i would like to ask for your help. how will i be able to extract part of the filename? FILENAME: 000_20071222083029135_evPDSN02.CANCEL i want to get only 000_20071222083029135.CANCEL Thanks and Good Day! :) (2 Replies)
Discussion started by: drco29
2 Replies

8. Programming

extraction from a path

Hi, Can you help me on this two problems? how can i get : from input: /ect/exp/hom/bin ==> output: exp and from input: aex1234 =====>output: ex thanks, (1 Reply)
Discussion started by: yeclota
1 Replies

9. Shell Programming and Scripting

AWK extraction

Hi all, Can anyone please help me in parsing the following file. Suppose the file is called, example.lst, and has the following content in it. (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) ... (3 Replies)
Discussion started by: harris2107
3 Replies

10. UNIX for Dummies Questions & Answers

help on file extraction

Hello, Im trying to extract a portion of a big file. Using unique pattern /occurrence , (ex. loginname1,logoff and loginname2,logoff ), I like to print the lines that contain the patterns and the lines between them. Also, create a file for every login occurrence. Thanks for everyone's... (1 Reply)
Discussion started by: apalex
1 Replies
Login or Register to Ask a Question