|
osdir.com mailing list archive F.A.Q. -since 2001! |
|
|
|
|
Date: Prev Next Date Index Thread: Prev Next Thread Index
Website Speed Performance Monitoring
I want to pull a random line from a file in a bash script. I can generate the
random number fine, but how would I go about pulling a single line from a file? I figure this is a one-line sed at worst, but I'm woefully lost by any sed that isn't s/find/replace/ and I can't figure what else I would use... fortune maybe? -- Kevan Shea -- Unsubscribe: send email to listar@xxxxxxxxxxxxxxxxxxxx and put 'unsubscribe lfs-chat' in the subject header of the message
Thread at a glance:
Previous Message by Date:Fw: Re: Dodgy Hardware (was Re: lost interrupt 8-|)Begin forwarded message: Date: Thu, 5 Sep 2002 22:03:56 +0200 From: "R. Bosch" <remy.bosch@xxxxxxxxx> To: blfs-support@xxxxxxxxxxxxxxxxxxxx, lfs-chat <lfs-chat@xxxxxxxxxxxxxxxxxxxx> Subject: Re: Dodgy Hardware (was Re: lost interrupt 8-|) On the date Thu, 5 Sep 2002 09:44:36 +0100 Declan Moriarty <declan.moriarty@xxxxxxxxxxx> thy wrote: > Mind you, the later SiS chips are much better and are even good, I'm told. Even better than VIA ;-) Next Message by Date:Re: Pull random line from a fileKevan Shea wrote in message: > I want to pull a random line from a file in a bash script. I can > generate the random number fine, but how would I go about pulling a > single line from a file? > > I figure this is a one-line sed at worst, but I'm woefully lost by > any sed that isn't s/find/replace/ and I can't figure what else I > would use... fortune maybe? > > -- > Kevan Shea Goofy idea, kinda just right off of the top of my head, but might just work depending on how many lines your wanting. I'm not familiar with the random function however. Just asume it's called random with arguments first and last (in the set) in the following example. __________________________________________________________ #!/bin/sh # Begin Random-line.sh VariableA=$(random 1 20) case "$VariableA" in 1) VariableB='whatever line your wanting to extract' ;; 2) VariableB='whatever line you want for 2' ;; ..... 20) VariableB='whatever line you want for 20' ;; esac Echo $VariableB # whatever else you want to do goes here and below....etc etc # End Random-line.sh ____________________________________________________________ I'm sure there is a much more elegant way to do this however..lol And the syntax is probably not even close to right...take a look at /etc/rc.d/init.d/template if you can actually use this method. Just a rather dumb idea, DJ -- Unsubscribe: send email to listar@xxxxxxxxxxxxxxxxxxxx and put 'unsubscribe lfs-chat' in the subject header of the message Previous Message by Thread:Re: Dodgy Hardware (was Re: lost interrupt 8-|)On the date Thu, 5 Sep 2002 09:44:36 +0100 Declan Moriarty <declan.moriarty@xxxxxxxxxxx> thy wrote: > Mind you, the later SiS chips are much better and are even good, I'm told. Even better than VIA ;-) Next Message by Thread:Re: Pull random line from a fileKevan Shea wrote in message: > I want to pull a random line from a file in a bash script. I can > generate the random number fine, but how would I go about pulling a > single line from a file? > > I figure this is a one-line sed at worst, but I'm woefully lost by > any sed that isn't s/find/replace/ and I can't figure what else I > would use... fortune maybe? > > -- > Kevan Shea Goofy idea, kinda just right off of the top of my head, but might just work depending on how many lines your wanting. I'm not familiar with the random function however. Just asume it's called random with arguments first and last (in the set) in the following example. __________________________________________________________ #!/bin/sh # Begin Random-line.sh VariableA=$(random 1 20) case "$VariableA" in 1) VariableB='whatever line your wanting to extract' ;; 2) VariableB='whatever line you want for 2' ;; ..... 20) VariableB='whatever line you want for 20' ;; esac Echo $VariableB # whatever else you want to do goes here and below....etc etc # End Random-line.sh ____________________________________________________________ I'm sure there is a much more elegant way to do this however..lol And the syntax is probably not even close to right...take a look at /etc/rc.d/init.d/template if you can actually use this method. Just a rather dumb idea, DJ -- Unsubscribe: send email to listar@xxxxxxxxxxxxxxxxxxxx and put 'unsubscribe lfs-chat' in the subject header of the message
|
|