rm -i and deleting files from an index table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rm -i and deleting files from an index table
# 8  
Old 11-21-2010
You can prevent list.ini from being listed in itself :

Code:
cd dustbin
ls | grep -v list.ini >list.ini
exec 3<list.ini
while read -u3 a
do rm -i $a
done
exec 3<&-
ls | grep -vf - list.ini >removed.txt
cp -p FileLocations.txt FileLocations.tmp
grep -vf removed.txt FileLocations.tmp >FileLocations.txt
rm removed.txt FileLocations.tmp list.ini

You can also just generate that file somewhere else so it will not be listed in that directory :
Code:
cd dustbin
ls >/tmp/list.ini
exec 3</tmp/list.ini
while read -u3 a
do rm -i $a
done
exec 3<&-
ls | grep -vf - /tmp/list.ini >removed.txt
cp -p FileLocations.txt FileLocations.tmp
grep -vf removed.txt FileLocations.tmp >FileLocations.txt
rm removed.txt FileLocations.tmp /tmp/list.ini


Last edited by ctsgnb; 11-21-2010 at 05:23 PM..
# 9  
Old 11-21-2010
Quote:
Originally Posted by ctsgnb
just rm -f dustbin.ini
Thanks, I just editted where the dustbin.ini thing was saved to be in root instead of dustbin and it also worked Smilie

Now got this working perfectly, thanks a bunch!
# 10  
Old 11-21-2010
in fact you have 2 choices :
1) prevent list.ini to be listed in itself
2) put list.ini somewhere else so it doesn't appear in the dustbin list
(see my previous post that i meanwhile have updated)
# 11  
Old 11-22-2010
Another problem i've realsied is that if I created two files with similiar names such as:

hello
hellothere

if I restored "hello" then "hellothere" also gets removed from file locations, i realise it is probbably to do with inserting a $ somewhere to make it so that what is check is hello only without any proceeding characters.

Thanks in advance.
# 12  
Old 11-22-2010
Quote:
Originally Posted by E-WAN
Another problem i've realsied is that if I created two files with similiar names such as:

hello
hellothere

if I restored "hello" then "hellothere" also gets removed from file locations, i realise it is probbably to do with inserting a $ somewhere to make it so that what is check is hello only without any proceeding characters.

Thanks in advance.
You should replace
Code:
ls | grep -vf - /tmp/list.ini >removed.txt

by this
Code:
ls | grep -vf - /tmp/list.ini | sed 's/.*/^&$/' >removed.txt

So this will also match beginning and end of line.

The thing you have to care of is the PATH since the matching must be exact.
(a same filename can be present in 2 differents path)

So i would advise you to work with absolute path name instead of relative (unless you are certain that the filenames in dustbin are going to be uniq by design or by the way they are generated so that they can be used as a key to retrieve the original location)

how would you manage the case :
Code:
/etc/file1 
/opt/file1
/usr/file1

have been removed...


(is there only 1 corresponding file1 in your dustbin directory ? even if those files have different content to eachother ? )
Or are the dustbin filenames generated so that they are uniq ?

Last edited by ctsgnb; 11-22-2010 at 01:02 PM..
# 13  
Old 11-22-2010
I have made it so all file names are unique, so for instance if there's a file in the trashcan called file then I can not send another file called file there, without removing the first instance.


I tried that code out and got the error

sed: -e expression #1, char 8: unterminated 's' command

Last edited by E-WAN; 11-22-2010 at 03:38 PM..
# 14  
Old 11-22-2010
Please post exactly what you did try (there is no "-e" option in the current version of my previous post) make sure you didn't forgot the last separator (here, a slash) in the substitution command s/.../.../

Last edited by ctsgnb; 11-22-2010 at 03:55 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Deleting unwanted text from a table

Hi everyone, I have a microbial diversity table in the format ;k__kingdom; p__phylum, etc, somer rows have descriptions before the :k__ (like the af028349.1 below) is there a way I can get rid of this text (which is different every time) and keep all the other columns? Thanks a bunch! ;... (1 Reply)
Discussion started by: Juan Gonzalez
1 Replies

2. Shell Programming and Scripting

Backup of index.* files

Sir, My server is hacked. Server administrator is saying that hacker used 0day CentOS kernal exploit to hack it. Now administrator updated the kernal and rebooted the server. But he is unable to cath the hacker, or how he initiated the process. So therefore i need your help in following... (5 Replies)
Discussion started by: SimonFrance
5 Replies

3. Shell Programming and Scripting

script to merge two files on an index

I have a need to merge two files on the value of an index column. input file 1 id filePath MDL_NUMBER 1 MFCD00008104.mol MFCD00008104 2 MFCD00012849.mol MFCD00012849 3 MFCD00037597.mol MFCD00037597 4 MFCD00064558.mol MFCD00064558 5 MFCD00064559.mol MFCD00064559 input file 2 ... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

4. UNIX for Dummies Questions & Answers

create table file from different files with index

Hi, I've several files with two collumns, where first collumn can be used as index. filename1 and filename2 how to create a file I should start with cat all files and extract first collumn to create an index? (4 Replies)
Discussion started by: sargotrons
4 Replies

5. UNIX for Dummies Questions & Answers

join files with numbered index

Hi all I´m a newbie so maybe this question will make someone mad. I am trying this command; join -a1 -11 file1 file2 > file3 file1 looks like: 1 2 3 4 5 6 7 8 9 10 11 file2: (4 Replies)
Discussion started by: awe1
4 Replies

6. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

7. Shell Programming and Scripting

Deleting table cells in a script

I'd like to use sed or awk to do this but I'm weak on both along with RE. Looking for a way with sed or awk to count for the 7th table data within a table row and if the condition is met to delete "<td>and everything in between </td>". Since the table header start on a specific line each time, that... (15 Replies)
Discussion started by: phpfreak
15 Replies

8. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

9. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

10. Shell Programming and Scripting

Help please!Split files according to index

Suppose I have a csv file like this: 27, california , A3 27, vermont, B6 27, ontario, B7 34, kansas, C9 34, washington, A2 How do I split this file into two files according to field1. file1: 27, california , A3 27, vermont, B6 27, ontario, B7 file2: 34, kansas, C9 34, washington, A2... (9 Replies)
Discussion started by: onthetopo
9 Replies
Login or Register to Ask a Question