Listing even numbered files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing even numbered files
# 1  
Old 12-09-2009
Lightbulb Listing even numbered files

Hi All,
Could you please help in this case?
Case: there's a directory 'CKMDB'
in this directory, there are 30 files named in this manner
1.txt 2.txt 3.txt .... 30.txt
Could you please guide me how to list only even numbered
files like 2.txt 4.txt etc ?
Thanks in advance.
# 2  
Old 12-09-2009
Code:
for i in `ls *txt`
do
k=`echo $i | cut -d"." -f1`
if [ $(($k%2)) -eq 0 ]
then
echo $i
fi
done


Last edited by zaxxon; 12-09-2009 at 05:31 AM.. Reason: code tags please, ty
# 3  
Old 12-09-2009
Code:
ls -1 *.txt| awk -F"." '$1 % 2 == 0 {print}'

# 4  
Old 12-09-2009
Quote:
Originally Posted by penchal_boddu
Code:
for i in `ls *txt`
do
k=`echo $i | cut -d"." -f1`
if [ $(($k%2)) -eq 0 ]
then
echo $i
fi
done

no need ls. its useless

---------- Post updated at 04:55 AM ---------- Previous update was at 04:50 AM ----------

Code:
cd CMDB; for i in ??.txt;  do num=${i%.txt};(( $((num%2==0)) )) && echo "$i"; done

# 5  
Old 12-09-2009
Code:
for i in `seq 2 2 30`
do
  ls -l $i.txt
done

or

Code:
seq 2 2 30 |xargs -i ls -l {}.txt

# 6  
Old 12-09-2009
Try:

Code:
ls  *[02468].txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

2. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

3. Shell Programming and Scripting

how to extract data from numbered files using linux in the numerical order-

Hi experts, I have a list of files containing forces as the only number as follows. Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Discussion started by: hamnsan
2 Replies

4. Shell Programming and Scripting

renaming numbered files

Hi there, I've got a set of files that are named as follows: image_N1_8letters.jpg image_N2_8letters.jpg ... image_N10_8letters.jpg image_N11_8letters.jpg .... image_N100_8letters.jpg image_N101_8letters.jpg with the "8letters" bit always consisting of 8 but always different... (3 Replies)
Discussion started by: kjartan
3 Replies

5. Shell Programming and Scripting

rename numbered files to numbered files with leading zeroes

Hi, I have some hundreds/thousands of files named logX.dat, where X can be any integer, and they are sequential, X ranges between 1 and any number: log1.dat log2.dat log3.dat log6.dat log10.dat ... log6000.dat I would like to rename them to scatter_params_0001.dat... (6 Replies)
Discussion started by: pau
6 Replies

6. 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

7. Shell Programming and Scripting

Need help with generating m3u files in numbered directories

Hello: First, I have no idea what to search for on this task, so I'll just spell it out. I have the Bible in Audio format and each book is in a directory of it's own. 01 to 66 accordingly. I need a script to walk through each of them and ls *.mp3 > directory|book.m3u without the preceding... (2 Replies)
Discussion started by: Habitual
2 Replies

8. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

9. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question