removing files with certain number in the first row

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing files with certain number in the first row
# 1  
Old 10-05-2009
removing files with certain number in the first row


I have 32000 files in a directory and want to remove those with first row beging with 0.00; file names are in numbers from 1 through 32000; I have coded the following but it gives me error:

while ( i <= 32000 )
if (head -1 $i ==0.00) rm $i

Well, i am sure even if this works it takes a long time. Any idea on modifying this or other methods (like find command)?

Thank you
# 2  
Old 10-05-2009
something like?

for file in $(ls -1 *)
found=$(head -1 $file | grep '^0\.00')
if [ "$found" ]; then
rm -f $file

# 3  
Old 10-05-2009
Thanks! but it gives me an error, i.e Variable syntax?!
# 4  
Old 10-05-2009
Don't do that!

If it gives you an error, show the error!!!
# 5  
Old 10-05-2009
Illegal variable name!! This is the only message shows up...
# 6  
Old 10-05-2009
I think this would work: -

grep ^0.00 * |  cut -d":" -f1 | xargs -i rm -f {}

---------- Post updated at 09:58 PM ---------- Previous update was at 09:43 PM ----------

Actually with 32000 files this would probably be safer: -

rm -f $(ls | xargs -i grep -l ^0.00 {})

# 7  
Old 10-05-2009
Dear Steadyonabix;

error message shows up for the second code, Illegal variable name!!
The first code seemingly removes the first field, but i want the file o be deleted.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Select and copy .csv files based on row and column number

Dear UNIX experts, I'm a command line novice working on a Macintosh computer (Bash shell) and have neither found advice that is pertinent to my problem on the internet nor in this forum. I have hundreds of .csv files in a directory. Now I would like to copy the subset of files that contains... (8 Replies)
Discussion started by: rcsapo
8 Replies

2. Shell Programming and Scripting

Removing large number of temp files

Hi All, I am having a situation now to delete a huge number of temp files created during run times approx. 16700+ files. We have never imagined that we will get this this much big list of files during run time. It worked fine for lesser no of files in the list. But when list is huge we are... (7 Replies)
Discussion started by: mad man
7 Replies

3. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

4. Shell Programming and Scripting

Paste many files with different row number in one file

Hi everybody I am trying to merge many files in one files using paste or pr command but I am not able to resolve this issue. The file are tab delimited like these: 1 4721519 4723118 1 5022468 5024918 1 7093519 7098118 2 19736573 19741172 2 21907973 21910572... (4 Replies)
Discussion started by: giuliangiuseppe
4 Replies

5. Shell Programming and Scripting

Get row number from file1 and print that row of file2

Hi. How can we print those rows of file2 which are mentioned in file1. first character of file1 is a row number.. for eg file1 1:abc 3:ghi 6:pqr file2 a abc b def c ghi d jkl e mno f pqr ... (6 Replies)
Discussion started by: Abhiraj Singh
6 Replies

6. UNIX for Dummies Questions & Answers

Finding row number along with length of row

I have a fixed length file and I want to find out row number along with row length. I have a program that give me the line length if it satisfy the condition; but i would like to add row number as well? How do I do that? while IFS= read -r line; do if ; then echo ${line} echo... (8 Replies)
Discussion started by: princetd001
8 Replies

7. Shell Programming and Scripting

The difference between end number in the early row and the start number in the next

Hi Power User, I'm trying to compute this kind of text file format: file1: jakarta 100 150 jakarta 170 210 beijing 220 250 beijing 260 280 beijing 290 320 new_york 330 350 new_york 370 420 tokyo 430 470 tokyo 480 ... (2 Replies)
Discussion started by: anjas
2 Replies

8. Shell Programming and Scripting

awk command : row by row merging of two files

I want to write a scrpit to merge files row wise (actually concatinating) main.txt X Y Z file 1 A B C file 2 1 2 3 now i want the script to check if the file1 is empty or not, if empty then make it like A B C 1 2 3 again to check if second file is empty if not do as done... (0 Replies)
Discussion started by: shashi792
0 Replies

9. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

10. Shell Programming and Scripting

removing a delimiter at the start of row

I Have this code while do column1=":`cat /home/test_inter.txt|head -${iCount1}|tail -1|cut -d "," -f2`" columnA=$columnA$column1 iCount1=`expr ${iCount1} + 1` done echo $columnA (2 Replies)
Discussion started by: nvuradi
2 Replies
Login or Register to Ask a Question