PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Read and delete one line from file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Read and delete one line from file

Réponse
 
LinkBack Outils de la discussion
Vieux 17/08/2006, 15h54   #1
chlori
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Read and delete one line from file

Hello

I have a shell scripting (bash) problem:

- File One gets lines added to it every few minutes.
- A shell script should copy the first line into File Two
and so on until File Two has 100 lines.
- Then File Three is created and the same is done there.

Any ideas how I could do that?

Thanks

--
chlori
  Réponse avec citation
Vieux 19/08/2006, 13h38   #2
Velásquez, Constantin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Read and delete one line from file

Sorry if I'm wrong but I think you should simply use 'for' and 'test'
instructions (man test and you'll find useful information about).

  Réponse avec citation
Vieux 19/08/2006, 13h41   #3
Robert Hull
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Read and delete one line from file

On Saturday 19 August 2006 13:38, Velásquez, Constantin
<cvelasquez.gnu@gmail.com> wrote in alt.os.linux:

> Sorry if I'm wrong but I think you should simply use 'for' and 'test'
> instructions (man test and you'll find useful information about).


WTF do you think you are talking about - your post doesn't give a clue.

http://www.plainfaqs.org/Why_Netiquette.html
--
Robert HULL

Archival or publication of this article on any part of thisishull.net
is without consent and is in direct breach of the Data Protection Act
  Réponse avec citation
Vieux 19/08/2006, 15h50   #4
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Read and delete one line from file

chlori (usenet314+arto.ch) writes:

> - File One gets lines added to it every few minutes.
> - A shell script should copy the first line into File Two and so on
> until File Two has 100 lines.
> - Then File Three is created and the same is done there.


You cold use named pipe (man mkfifo):

$ mkfifo sh17

then configure the app (or whatever) to write lines to that pipe and
finally your shell script would look like:

NUM=0
while NFS= read LINE; do
read
printf '%s\n' "$LINE" >file-$(($NUM / 100))
NUM=$(($NUM + 1))
done <sh17

or something similar. I hope you got the idea.


--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 19/08/2006, 16h11   #5
Walter Mautner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Read and delete one line from file

chlori enlightened us alt.os.linux - (ab)users with:

> Hello
>
> I have a shell scripting (bash) problem:
>
> - File One gets lines added to it every few minutes.
> - A shell script should copy the first line into File Two
> and so on until File Two has 100 lines.


What do you want to do with the first line after it is copied to the 2nd
file? You probably do not want to add the 1st line to file2 every
second or faster.
Will file1 have to hold a threshold of lines or may it be drained from
the backside until empty, like a FIFO?

> - Then File Three is created and the same is done there.
>
> Any ideas how I could do that?
>

What do you really want to do?
--
vista policy violation: Microsoft optical mouse found penguin patterns
on mousepad. Partition scan in progress to remove offending
incompatible products. Reactivate MS software.
Linux 2.6.17-mm1,Xorg7.1/nvidia [LinuxCounter#295241,ICQ#4918962]
  Réponse avec citation
Vieux 20/08/2006, 00h13   #6
Loki Harfagr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Read and delete one line from file

Le Thu, 17 Aug 2006 16:54:53 +0200, chlori a écrit:

> Hello
>
> I have a shell scripting (bash) problem:
>
> - File One gets lines added to it every few minutes.
> - A shell script should copy the first line into File Two
> and so on until File Two has 100 lines.
> - Then File Three is created and the same is done there.
>
> Any ideas how I could do that?


How could you do what ?
Wouldn't it be easier to post the exact text of this homework ?
Just because, as it is described here it doesn't make much sense to me.
(emphasis on me, as it 'd be that I just can't read fast english
as much as I can write broken english :-)

What I understand from your premices is that you'll fill a
file File(N+1) with the content of the solely first line from
File(N). Seems an easy way to slowly fill a disk with a
numb line )

Maybe the training exercise was just about that, see if you
could think that the algorithm was dumb ?

Or is it just you didn't post the *real* text ?


Anyway, the answer to your post could be something based on :

This is the file feeding part :

(while true; do sleep 1 && date +%F%X >> /tmp/_numb ; done) &

This is the triggering bot :

(( 100 < $(wc -l /tmp/_numb | cut -d' ' -f1 ) )) && echo "CHANGEFILE"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h13.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10432 seconds with 14 queries