Thread Tools
Old November 10, 2003, 10:58   #1
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
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."
Kaak is offline  
Old November 10, 2003, 11:36   #2
Ari Rahikkala
King
 
Ari Rahikkala's Avatar
 
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
__________________
This is Shireroth, and Giant Squid will brutally murder me if I ever remove this link from my signature | In the end it won't be love that saves us, it will be mathematics | So many people have this concept of God the Avenger. I see God as the ultimate sense of humor -- SlowwHand
Ari Rahikkala is offline  
Old November 10, 2003, 12:06   #3
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 10, 2003, 12:10   #4
Paul Hanson
King
 
Paul Hanson's Avatar
 
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...
__________________
"Paul Hanson, you should give Gibraltar back to the Spanish" - Paiktis, dramatically over-estimating my influence in diplomatic circles.

Eyewerks - you know you want to visit. No really, you do. Go on, click me.
Paul Hanson is offline  
Old November 10, 2003, 12:40   #5
Urban Ranger
NationStatesApolyton Storywriters' GuildNever Ending Stories
Deity
 
Urban Ranger's Avatar
 
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."
Urban Ranger is offline  
Old November 10, 2003, 12:43   #6
Q Classic
Emperor
 
Q Classic's Avatar
 
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
Q Classic is offline  
Old November 10, 2003, 12:46   #7
Paul Hanson
King
 
Paul Hanson's Avatar
 
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.
__________________
"Paul Hanson, you should give Gibraltar back to the Spanish" - Paiktis, dramatically over-estimating my influence in diplomatic circles.

Eyewerks - you know you want to visit. No really, you do. Go on, click me.
Paul Hanson is offline  
Old November 10, 2003, 13:49   #8
Whaleboy
NationStatesAlpha Centauri Democracy GameACDG The Cybernetic ConsciousnessMac
Prince
 
Whaleboy's Avatar
 
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:
Whaleboy is offline  
Old November 10, 2003, 14:01   #9
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
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."
Kaak is offline  
Old November 10, 2003, 23:35   #10
Urban Ranger
NationStatesApolyton Storywriters' GuildNever Ending Stories
Deity
 
Urban Ranger's Avatar
 
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."
Urban Ranger is offline  
Old November 11, 2003, 05:11   #11
Ari Rahikkala
King
 
Ari Rahikkala's Avatar
 
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...
__________________
This is Shireroth, and Giant Squid will brutally murder me if I ever remove this link from my signature | In the end it won't be love that saves us, it will be mathematics | So many people have this concept of God the Avenger. I see God as the ultimate sense of humor -- SlowwHand
Ari Rahikkala is offline  
Old November 11, 2003, 05:18   #12
Fve Crathva
Warlord
 
Fve Crathva's Avatar
 
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.
Fve Crathva is offline  
Old November 11, 2003, 06:47   #13
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 11, 2003, 06:52   #14
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 11, 2003, 06:55   #15
Paul Hanson
King
 
Paul Hanson's Avatar
 
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.
__________________
"Paul Hanson, you should give Gibraltar back to the Spanish" - Paiktis, dramatically over-estimating my influence in diplomatic circles.

Eyewerks - you know you want to visit. No really, you do. Go on, click me.
Paul Hanson is offline  
Old November 11, 2003, 07:18   #16
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 11, 2003, 07:27   #17
Pekka
Emperor
 
Pekka's Avatar
 
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.
Pekka is offline  
Old November 11, 2003, 08:42   #18
Ari Rahikkala
King
 
Ari Rahikkala's Avatar
 
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...
__________________
This is Shireroth, and Giant Squid will brutally murder me if I ever remove this link from my signature | In the end it won't be love that saves us, it will be mathematics | So many people have this concept of God the Avenger. I see God as the ultimate sense of humor -- SlowwHand
Ari Rahikkala is offline  
Old November 11, 2003, 11:20   #19
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 11, 2003, 11:41   #20
Ari Rahikkala
King
 
Ari Rahikkala's Avatar
 
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...
__________________
This is Shireroth, and Giant Squid will brutally murder me if I ever remove this link from my signature | In the end it won't be love that saves us, it will be mathematics | So many people have this concept of God the Avenger. I see God as the ultimate sense of humor -- SlowwHand
Ari Rahikkala is offline  
Old November 11, 2003, 11:51   #21
Whaleboy
NationStatesAlpha Centauri Democracy GameACDG The Cybernetic ConsciousnessMac
Prince
 
Whaleboy's Avatar
 
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:
Whaleboy is offline  
Old November 11, 2003, 12:13   #22
Provost Harrison
Apolytoners Hall of FameCivilization IV PBEMPolyCast Team
Deity
 
Provost Harrison's Avatar
 
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
Provost Harrison is offline  
Old November 11, 2003, 23:32   #23
Urban Ranger
NationStatesApolyton Storywriters' GuildNever Ending Stories
Deity
 
Urban Ranger's Avatar
 
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."
Urban Ranger is offline  
Old November 12, 2003, 03:31   #24
Fve Crathva
Warlord
 
Fve Crathva's Avatar
 
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
Fve Crathva is offline  
Old November 12, 2003, 03:46   #25
Nubclear
NationStatesCall to Power II Democracy GameInterSite Democracy Game: Apolyton TeamRise of Nations MultiplayerACDG The Human HiveNever Ending StoriesACDG The Free DronesACDG The Cybernetic ConsciousnessGalCiv Apolyton EmpireACDG3 SpartansC4DG Team Alpha CentauriansCiv4 SP Democracy GameDiplomacyAlpha Centauri PBEMCivilization IV PBEMAlpha Centauri Democracy GameACDG Peace
PolyCast Thread Necromancer
 
Nubclear's Avatar
 
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
Nubclear is offline  
Old November 12, 2003, 04:09   #26
Fve Crathva
Warlord
 
Fve Crathva's Avatar
 
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
Fve Crathva is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 08:13.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team