Bash - Redondance dans un fichier
Résolu
Remad
Messages postés
1662
Date d'inscription
Statut
Membre
Dernière intervention
-
Remad Messages postés 1662 Date d'inscription Statut Membre Dernière intervention - 8 nov. 2011 à 21:31
Remad Messages postés 1662 Date d'inscription Statut Membre Dernière intervention - 8 nov. 2011 à 21:31
A voir également:
- Bash - Redondance dans un fichier
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Fichier rar - Guide
- Fichier .dat - Guide
3 réponses
en changeant le flux de redirection peut être ?
un simple au lieu d'un double.
mv -iv $* > $HOME/backup/.backup
au lieu de
mv -iv $* >> $HOME/backup/.backup
un simple au lieu d'un double.
mv -iv $* > $HOME/backup/.backup
au lieu de
mv -iv $* >> $HOME/backup/.backup
Remad
Messages postés
1662
Date d'inscription
Statut
Membre
Dernière intervention
708
Sa ne pourra pas marcher, c'est pour faire une genre de corbeille en bash pour l'université, des fichiers peuvent être déplacés a des moments différents.
Salut,
Comment faire en bash pour supprimer les lignes redondantes dans un fichier?
;-))
Comment faire en bash pour supprimer les lignes redondantes dans un fichier?
sort -u fichier_redondant > fichier_épuré
;-))
Sa fonctionne! maintenant j'ai un nouveau soucis avec la commande mv:
Quand je lance la commande
Elle execute la fonction
mais elle insrit dans le fichier $HOME/backup/.backup ceci:
'blah.txt' -> '/home8/p09267388/backup/blah.txt'
'/home8/p09267388/ablah.txt' -> '/home8/p09267388/backup/ablah.txt'
comment faire pour qu'elle inscrive ceci?
'/home8/p09267388/blah.txt' -> '/home8/p09267388/backup/blah.txt'
'/home8/p09267388/ablah.txt' -> '/home8/p09267388/backup/ablah.txt'
Quand je lance la commande
bash ./MSc/Bash/backup ablah.txt blah.txt
Elle execute la fonction
mv -iv $PWD/$* $HOME/backup/ >> $HOME/backup/.backup
mais elle insrit dans le fichier $HOME/backup/.backup ceci:
'blah.txt' -> '/home8/p09267388/backup/blah.txt'
'/home8/p09267388/ablah.txt' -> '/home8/p09267388/backup/ablah.txt'
comment faire pour qu'elle inscrive ceci?
'/home8/p09267388/blah.txt' -> '/home8/p09267388/backup/blah.txt'
'/home8/p09267388/ablah.txt' -> '/home8/p09267388/backup/ablah.txt'
Voyez-vous une optimisation possible dans mon code?
#!/bin/bash #Pierre cybard - p09267388 if [ -d $HOME/backup ] #test if a backup directory exists then if [ $# -eq 0 ] #if no parameters then echo -n "No parameters given. Do you want to backup the current folder? Y/N: " read answer if [ $answer == "Y" ] || [ $answer == "y" ] || [ $answer == "Yes" ] || [ $answer == "YES" ] || [ $answer == "yes" ] #Yes = backup the current folder / other = do nothing then chmod -R 700 $HOME/backup #restore the write permission on the folder mv -iv $PWD/ $HOME/backup/ >> $HOME/backup/.backup #move the current folder, add a line on the .backup file sort -u $HOME/backup/.backup > $HOME/backup/.backupTemp #sorting by name, avoiding redundancy, on a temporary file mv $HOME/backup/.backupTemp $HOME/backup/.backup #move the temporary file to the .backup file chmod -R 500 $HOME/backup #restore the limited permissions fi else #if parameters chmod -R 700 $HOME/backup #restore the write permission on the folder for ARG in "$@" #for every parameters do mv -iv $PWD/$ARG $HOME/backup/ >> $HOME/backup/.backup #move the file/folder and add a line on the .backup file done sort -u $HOME/backup/.backup > $HOME/backup/.backupTemp #sorting by name, avoiding redundancy, on a temporary file mv $HOME/backup/.backupTemp $HOME/backup/.backup #move the temporary file to the .backup file chmod -R 500 $HOME/backup #restore the limited permissions fi else #if backup directory do not exists echo "The backup folder do not exist. Please use the initialise function." fi