November 10, 2003, 10:58
|
#1
|
King
Local Time: 06:13
Local Date: November 2, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
|
Help with unix commands
I'm trying to use sed, and it asks me to print all lines where b-days are in November or December. The way the input file is set up,
sed -n '/^[^:]*:[^:]*:[^:]*:11/p' databook
gives me the b-days in november, i just don't know how to make it do an "or" to get both. any ideas?
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)
"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
|
|
|
|
November 10, 2003, 11:36
|
#2
|
King
Local Time: 15:13
Local Date: November 2, 2010
Join Date: Oct 1999
Location: Shireroth
Posts: 2,792
|
I dunno how to do this portably, but in GNU sed you can use \| to match "either", like so:
/^[^:]*:[^:]*:[^:]*:\(11\)\|\(12\)/p
|
|
|
|
November 10, 2003, 12:06
|
#3
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
Thankyou for reminding me why I never have used Linux...
__________________
Speaking of Erith:
"It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith
|
|
|
|
November 10, 2003, 12:10
|
#4
|
King
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Aug 1999
Location: Dilbert
Posts: 1,839
|
Just because you're not l33t enough...
|
|
|
|
November 10, 2003, 12:40
|
#5
|
Deity
Local Time: 20:13
Local Date: November 2, 2010
Join Date: May 1999
Location: The City State of Noosphere, CPA special envoy
Posts: 14,606
|
Quote:
|
Originally posted by Provost Harrison
Thankyou for reminding me why I never have used Linux...
|
That's just a regular expression. Not more complicated than most of the biochem stuff.
__________________
(\__/) 07/07/1937 - Never forget
(='.'=) "Claims demand evidence; extraordinary claims demand extraordinary evidence." -- Carl Sagan
(")_(") "Starting the fire from within."
|
|
|
|
November 10, 2003, 12:43
|
#6
|
Emperor
Local Time: 07:13
Local Date: November 2, 2010
Join Date: Apr 1999
Location: The cities of Orly and Nowai
Posts: 4,228
|
paul hanson
provost harrison
both with eu markings...
confusing.
__________________
B♭3
|
|
|
|
November 10, 2003, 12:46
|
#7
|
King
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Aug 1999
Location: Dilbert
Posts: 1,839
|
You think that's bad? We both spend a lot of time in the same city as well.
|
|
|
|
November 10, 2003, 13:49
|
#8
|
Prince
Local Time: 12:13
Local Date: November 2, 2010
Join Date: Jan 2003
Location: Please make all cheques payable to Whaleboy
Posts: 853
|
God I'm so glad I'm back to WinXP
__________________
"I work in IT so I'd be buggered without a computer" - Words of wisdom from Provost Harrison
"You can be wrong AND jewish" - Wiglaf :love:
|
|
|
|
November 10, 2003, 14:01
|
#9
|
King
Local Time: 06:13
Local Date: November 2, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
|
thanks
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)
"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
|
|
|
|
November 10, 2003, 23:35
|
#10
|
Deity
Local Time: 20:13
Local Date: November 2, 2010
Join Date: May 1999
Location: The City State of Noosphere, CPA special envoy
Posts: 14,606
|
Quote:
|
Originally posted by Whaleboy
God I'm so glad I'm back to WinXP
|
For what? You don't need to know regex to use *nix.
__________________
(\__/) 07/07/1937 - Never forget
(='.'=) "Claims demand evidence; extraordinary claims demand extraordinary evidence." -- Carl Sagan
(")_(") "Starting the fire from within."
|
|
|
|
November 11, 2003, 05:11
|
#11
|
King
Local Time: 15:13
Local Date: November 2, 2010
Join Date: Oct 1999
Location: Shireroth
Posts: 2,792
|
Ah, of course, Doing it this way you don't need GNU extensions, AFAICT:
/^[^:]*:[^:]*:[^:]*:1[12]/p
Every time I use nonstandard extensions (such as the stuff GNU has added to so many *nix tools) anywhere I hear a little BSD daemon shouting at me about hypocrisy...
|
|
|
|
November 11, 2003, 05:18
|
#12
|
Warlord
Local Time: 05:13
Local Date: November 2, 2010
Join Date: Apr 2001
Posts: 288
|
Out of curiosity, would this also work?
/^(.*?:){3}1[12]/p
SP
__________________
I got the Jete from C.C. Sabathia. : Jon Miller
Last edited by Fve Crathva; November 11, 2003 at 06:18.
|
|
|
|
November 11, 2003, 06:47
|
#13
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
Quote:
|
Originally posted by Paul Hanson
Just because you're not l33t enough...
|
That is true, I am always on time
|
|
|
|
November 11, 2003, 06:52
|
#14
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
Quote:
|
Originally posted by Paul Hanson
You think that's bad? We both spend a lot of time in the same city as well.
|
Except you spend your weekdays in Hull working (well, uni) and home in Lincolnshire on the weekends, whereas I spend my weekdays in Lincolnshire working and my weekends at home in Hull
|
|
|
|
November 11, 2003, 06:55
|
#15
|
King
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Aug 1999
Location: Dilbert
Posts: 1,839
|
Well, I'm actually spending more time in Hull this year. Not because I've developed an affinity for the place, but because my family drive me nuts.
|
|
|
|
November 11, 2003, 07:18
|
#16
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
Enjoy Hull...some of us are having to spend more time in Grimsby. It makes you appreciate the place
__________________
Speaking of Erith:
"It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith
|
|
|
|
November 11, 2003, 07:27
|
#17
|
Emperor
Local Time: 15:13
Local Date: November 2, 2010
Join Date: Feb 2002
Location: Xrr ZRRRRRRR!!
Posts: 6,484
|
kaak@kaak.net>I commaaand youu to obeyyy they woord of the Lord, which tells you to CHANGE DIRECTORY!
There are soem more basic commands, so what do you need?
__________________
In da butt.
"Do not worry if others do not understand you. Instead worry if you do not understand others." - Confucius
THE UNDEFEATED SUPERCITIZEN w:4 t:2 l:1 (DON'T ASK!)
"God is dead" - Nietzsche. "Nietzsche is dead" - God.
|
|
|
|
November 11, 2003, 08:42
|
#18
|
King
Local Time: 15:13
Local Date: November 2, 2010
Join Date: Oct 1999
Location: Shireroth
Posts: 2,792
|
Well, it was inevitable, I decided to start testing these regexes...
$ cat databook
0:04:01:10:wh00t
0:10:12:05:l33t-2003
0:01:01:01:666
0:04:15:11:324
0:04:15:12:k3wl
$ sed -n '/^[^:]*:[^:]*:[^:]*:11/p' databook
0:04:15:11:324
This one prints November's records, as it's supposed to...
$ sed -n '/^[^:]*:[^:]*:[^:]*:\(11\)\|\(12\)/p' databook
0:10:12:05:l33t-2003
0:04:15:11:324
0:04:15:12:k3wl
I'l figure out why this one produces wrong results later, if I can be bothered... (it probably picks up the 12 in the third column for some reason)
$ sed -n '/^[^:]*:[^:]*:[^:]*:1[12]/p' databook
0:04:15:11:324
0:04:15:12:k3wl
This one does exactly what it's supposed to do.
$ sed -n '/^(.*?:){3}1[12]/p' databook
And this one doesn't seem to do anything... however, a fixed version of it does:
$ sed -n '/^\(.*:\)\{3\}1[12]/p' databook
0:04:15:11:324
0:04:15:12:k3wl
As does a version that might be safer, or then not, I'm not really sure:
$ sed -n '/^\([^:]*:\)\{3\}1[12]/p' databook
0:04:15:11:324
0:04:15:12:k3wl
No, I for one have not understood sed's rules about what needs to be escaped and what not in regexes...
|
|
|
|
November 11, 2003, 11:20
|
#19
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
You're all such a bunch of nerds...
__________________
Speaking of Erith:
"It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith
|
|
|
|
November 11, 2003, 11:41
|
#20
|
King
Local Time: 15:13
Local Date: November 2, 2010
Join Date: Oct 1999
Location: Shireroth
Posts: 2,792
|
I'm almost ashamed about the acts of l33tism I committed. I guess I've picked it up at the Gentoo forums where the user levels are in l33t, probably (hopefully) as a joke...
|
|
|
|
November 11, 2003, 11:51
|
#21
|
Prince
Local Time: 12:13
Local Date: November 2, 2010
Join Date: Jan 2003
Location: Please make all cheques payable to Whaleboy
Posts: 853
|
What is l33t?
__________________
"I work in IT so I'd be buggered without a computer" - Words of wisdom from Provost Harrison
"You can be wrong AND jewish" - Wiglaf :love:
|
|
|
|
November 11, 2003, 12:13
|
#22
|
Deity
Local Time: 13:13
Local Date: November 2, 2010
Join Date: Feb 2000
Location: Germans own my soul.
Posts: 14,861
|
Very, very sad Whaleboy, very, very sad. You've proven your credibility by not knowing what it is
__________________
Speaking of Erith:
"It's not twinned with anywhere, but it does have a suicide pact with Dagenham" - Linda Smith
|
|
|
|
November 11, 2003, 23:32
|
#23
|
Deity
Local Time: 20:13
Local Date: November 2, 2010
Join Date: May 1999
Location: The City State of Noosphere, CPA special envoy
Posts: 14,606
|
He's just playing dumb Rich.
__________________
(\__/) 07/07/1937 - Never forget
(='.'=) "Claims demand evidence; extraordinary claims demand extraordinary evidence." -- Carl Sagan
(")_(") "Starting the fire from within."
|
|
|
|
November 12, 2003, 03:31
|
#24
|
Warlord
Local Time: 05:13
Local Date: November 2, 2010
Join Date: Apr 2001
Posts: 288
|
^\([^:]*:\)\{3\}1[12] would be safer than ^\(.*:\)\{3\}1[12], but something can be said for using unsafe REs as an input debugging tool; does sed not know about non-greedy matching?
I think I'll stick to Perl. Oh, yes.
SP
__________________
I got the Jete from C.C. Sabathia. : Jon Miller
|
|
|
|
November 12, 2003, 03:46
|
#25
|
PolyCast Thread Necromancer
Local Time: 12:13
Local Date: November 2, 2010
Join Date: Jul 2002
Location: We are all Asher now.
Posts: 1,437
|
([3^4]*1:2(4)])$^¨b12
|
|
|
|
November 12, 2003, 04:09
|
#26
|
Warlord
Local Time: 05:13
Local Date: November 2, 2010
Join Date: Apr 2001
Posts: 288
|
Sicko.
SP
__________________
I got the Jete from C.C. Sabathia. : Jon Miller
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
All times are GMT -4. The time now is 08:13.
|
|