Regex question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex question
# 8  
Old 09-27-2018
Now - OpenVMS definitely is NOT "almost same to other other operating systems." Refer to their help system (unfortunately it's quite some time so I can't remember the correct syntax) about what options and regexes they accept.


Quote:
Originally Posted by boncuk
. . .
I tried Rudi's command on sun solaris,
. . .

Do you have access to GNU sed on your system?

You could try the -r option, which on several systems is equivalent to -E.

Applied to your a.txt file from post#6 on Ubuntu 18.04:

Code:
sed  -E '/^[0-9]{8}(0[1357]|1[01])/d' file
000000000000
433483433339
167750000010
sed  '/^[0-9]\{8\}\(0[1357]\|1[01]\)/d' file
000000000000
433483433339
167750000010

EDIT: on FreeBSD 9.0-RELEASE, the BRE sed fails, but
Code:
sed  -E '/^[0-9]{8}(0[1357]|1[01])/d' file
000000000000
433483433339
167750000010

This works on my FreeBSD:
Code:
sed  '/^[0-9]\{8\}0[1357]/d; /^[0-9]\{8\}1[01]/d' file


Last edited by RudiC; 09-27-2018 at 04:40 AM..
# 9  
Old 09-27-2018
Just using standard sed features and avoiding cases where systems allowing EREs or BREs make a difference, both of the following seem to also do what you want:
Code:
sed -e '/^........0[1357]/d' -e '/^........1[01]/d' a.txt

and:
Code:
sed '/^........0[1357]/d;/^........1[01]/d' a.txt

But, I have no experience with openVMS, so I can't say whether or not either of these will work there.
# 10  
Old 09-27-2018
sorry the browswer not putting code tags around the code when I click on button , so I am adding them manually hope it works.
can someone help me on my sed command please?

I am using sun solaris and Linux , what I want is SED to print any string (or output it to a file preferably) that does not have either "01","03","05","07","10" or "11" on the 9th and 10th position .
e.g from the file below I only want these three lines


Code:
433483433339
167710001710
167730600000


Code:
$cat a.txt
 000000001000
 433483433339 <<< print this since 33 is at 9th and 10th pos
 121121211100 
 167710001710 <<< print this since 17 is at 9th and 10th pos
 167735250310
 167735260510
 167735280710
 167730600000 <<< print this since 00 is at 9th and 10th pos

------ Post updated at 10:07 AM ------

Quote:
Originally Posted by Don Cragun
Just using standard sed features and avoiding cases where systems allowing EREs or BREs make a difference, both of the following seem to also do what you want:
Code:
sed -e '/^........0[1357]/d' -e '/^........1[01]/d' a.txt

and:
Code:
sed '/^........0[1357]/d;/^........1[01]/d' a.txt

But, I have no experience with openVMS, so I can't say whether or not either of these will work there.


awesome this one worked

------ Post updated at 10:08 AM ------

how does this command works though .. I understand each parts but how the output of one gets piped to the other?


Code:
sed -e '/^........0[1357]/d' -e '/^........1[01]/d' a.txt

# 11  
Old 09-27-2018
Quote:
Originally Posted by boncuk
... ... ...

Quote:
Originally Posted by Don Cragun
Just using standard sed features and avoiding cases where systems allowing EREs or BREs make a difference, both of the following seem to also do what you want:
Code:
sed -e '/^........0[1357]/d' -e '/^........1[01]/d' a.txt

and:
Code:
sed '/^........0[1357]/d;/^........1[01]/d' a.txt

But, I have no experience with openVMS, so I can't say whether or not either of these will work there.
awesome this one worked

------ Post updated at 10:08 AM ------

how does this command works though .. I understand each parts but how the output of one gets piped to the other?


Code:
sed -e '/^........0[1357]/d' -e '/^........1[01]/d' a.txt

There is a single sed command invocation here containing two editing commands. No piping is involved. The first editing command deletes every line that contains 01, 03, 05m or 07 as the 9th and 10th characters on a line. If that command didn't delete the line, the 2nd editing commands deletes every line that contains 10 or 11 as the 9th and 10th characters on a line. If neither of those editing commands deleted the input line, the default sed action is to copy the input line to standard output.

When there are two editing commands to be performed by one invocation of sed, each of those editing commands can be introduced as separate -e option arguments (as shown in the first sed command above).

Many sed commands (including the delete command) can be entered as a single -e option argument by separating them with a semicolon. And, if only one editing command argument is needed, including the actual -e option is optional (as shown in the second sed command above).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex Question

Hi I am trying to match lines having following string BIND dn="uid= putting something like this is not working : /\sBIND dn="uid=/ Any suggestion. Thanks. John (9 Replies)
Discussion started by: john_prince
9 Replies

2. Shell Programming and Scripting

regex question

Hi guys, I am trying to "grep" or "egrep" the following entry out of the file using regex: MACCDB1 or MACCDB2 The problem is that the file might contain other entries which start with "MACCDB" string. I was trying to use regex to "grep" the exact pattern but it fails to output the correct... (2 Replies)
Discussion started by: aoussenko
2 Replies

3. Shell Programming and Scripting

regex question

Hi guys, I have a file in the following format: cmpr5551 cmpr6002 cmpr93 anne 5454 bbro 434 cmprsvc cmprsvc7 ffgi55 vefe99 cmprsvc8 cmprsvc9 I need to "grep" only the entries which start with "cmpr" followed by the number. All other entries should be excluded. I was trying to use... (3 Replies)
Discussion started by: aoussenko
3 Replies

4. Shell Programming and Scripting

RegEX question

Hi, I am trying to write a regex for myscript and need some input from experts. here is what I must grep for TICKET{Sapce}{Space}{hyphen} so here is the example data TICKET 34554, CT-12345, TICKET 12345: some text here TICKET 2342, CT-12345, MA-12344: some text here TICKET... (5 Replies)
Discussion started by: rider29
5 Replies

5. UNIX for Dummies Questions & Answers

regex question

I have dates in mm/dd/yy format that I wish to convert to yy-mm-dd format. ()/()/() finds them, but when I try to replace with $3-$1-$2 both kate and kwrite treat it as a text literal. (2 Replies)
Discussion started by: porphyry5
2 Replies

6. Shell Programming and Scripting

Question on regex with * and .

I have a basic question regarding * and . while using regex: # echo 3 | grep ^*$ 3 I think I understood why it outputs "3" here (because '*' matches zero or more of the previous character) but I don't understand the output of the following command: # echo 3 | grep ^.$ # I thought I... (7 Replies)
Discussion started by: mirage
7 Replies

7. Shell Programming and Scripting

regex question

Hi, im sure this is really simple but i cant quite figure it out. how do i test against a word at the beginning of the line but up to the point of a delimiter i.e. ":" for example if i wanted to test against the user in the /etc/passwd file peter:x:101:100:peters account:/var/peter:/bin/sh ... (3 Replies)
Discussion started by: hcclnoodles
3 Replies

8. Shell Programming and Scripting

regex question

Hi I have a question on regex There is a line in a script like my_file="$(echo SunMonTueWed | sed "s//_&g") " My question what does the expression _&g do. Obviously in this example the output is _Sun_Mon_Tue_Wed Another question can i use some trick to get the result like... (3 Replies)
Discussion started by: xiamin
3 Replies

9. Shell Programming and Scripting

regex question

I have a simple file test.out that contains data in the form of key1=A|shift1 key2=B|shift2 key3=C|shift3 and so on. I need to get it to print A B C I can do it using lookbehind assertion such as this ( ?<==)() yet I was wondering if there is another way of mutching single... (8 Replies)
Discussion started by: arushunter
8 Replies

10. UNIX for Dummies Questions & Answers

regex question

hi, i got a problem with understanding regular expressions. what i wanna do is scanning the wtmp logfile for ips and if a specific ip is echoed id like to be a part of a text to be assigned to it. the scanning is done with #! /bin/bash cat wtmp | strings | egrep -o "+\.+\.+\." | sort -u... (6 Replies)
Discussion started by: rocketkids
6 Replies
Login or Register to Ask a Question