Sponsored Content
Top Forums Shell Programming and Scripting Conditional File Selection From a Directory Post 302849823 by shekhar2010us on Tuesday 3rd of September 2013 11:54:57 AM
Old 09-03-2013
This is how I am calculating the score of each file... splitting the filename and adding the parts and multiply it with the filesize....

Now what I am not able to do is to take files with 50 highest scores for every hour in the day ??

Code:
cd <folder>

for file in *.*
do
  
  # get the filename
  filename=$(stat -r $file | awk -F" " '{print $16}' )
  
  # get the filesize
  filesize=$(stat -r $file | awk -F" " '{print $8}' )
  
  # split the filename and store in an array
  IFS='_' read -a arr <<< "${filename}"
  
  # find the sum of the filename splitted float values
  total=0
  for i in ${arr[@]}; do
    total=`echo $total + $i | bc`;
  done

  # find the score of the file = (filesize * sum of the floats)
  score=$(echo $filesize $total | awk '{printf "%4.3f",$1*$2}')

done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Random lines selection form a file.

>cat data.dat 0001 Robbert 0002 Nick 0003 Mark ....... 1000 Jarek (3 Replies)
Discussion started by: McLan
3 Replies

2. Shell Programming and Scripting

Random File Selection and Moving

OK, I am stumpped. I have this shell Script that I want to randomly select a file with the extention of .sct. Then using a portion of its file name select the six related .mot files. Then move them all to another folder. I also need a user input form for the number of .SCT files to randomly select... (6 Replies)
Discussion started by: stak1993
6 Replies

3. Shell Programming and Scripting

Perform Operations on One File Conditional on Data in Another File

Hello all, I am looking for a solution to the following problem. Perl or python solutions also welcome. Given this input: And this input: I want to get this output. The rule being that if the number in the first file is < 0.9, then the corresponding two columns on... (2 Replies)
Discussion started by: hydrabane
2 Replies

4. Shell Programming and Scripting

conditional append one line in file.

Hi, Unix gurus, I have a requirement as following: checking existing file, if the file only contain one line. then append "No data" else keep existing file as is. can i achieve this by in command line without write a script. :wall: Thanks in advance. (4 Replies)
Discussion started by: ken002
4 Replies

5. Shell Programming and Scripting

Conditional File Splitting in Unix

Hello Guys, I am new to Unix and i got one requirement where I need to split my file into maximum 5 files on below conditions, if they are splitted into less than 5 then also we are fine. Columns D value should appear in a single file only and shouldn't continue in other files. ... (1 Reply)
Discussion started by: Rizzu155
1 Replies

6. Programming

Conditional replace after reading in a file

I need to read the contents of a file. Then I need to grep for a keyword and replace part of the grepped line based on the condition of previous and present line. Example input file: V { port1 = P; port2 = 0; shift_port = P0; /* if next shift_port is P0 I need... (7 Replies)
Discussion started by: naveen@
7 Replies

7. UNIX for Dummies Questions & Answers

Random selection of subset of sample from file

Hello Could you please help me to find a code that can randomly select 1224 lines from a file of 12240 and make tn output with 1224 line each. my input is txt file with 12240 lines like : 13474 999003507 0 0 2 -9 13475 999003508 0 0 2 -9 13476 999003509 0 0 1 -9 13477 999003510 0 0 1 -9 ... (7 Replies)
Discussion started by: biopsy
7 Replies

8. Shell Programming and Scripting

Conditional splitting in more file

Dear All, I was wondering in how split one file in multiple file in a conditional way. Briefly, I have a file like this: >Id1 textA >Id2 textBand my outputs file (2 in this case) shoul be: Id1 >Id1 textAId2 >Id2 textBhope you may help me. Best G (5 Replies)
Discussion started by: giuliangiuseppe
5 Replies

9. Shell Programming and Scripting

awk to format file with conditional split

In the awk below I am splitting $7 on the : (colon) then - (hyphen) as array a. The word chr is printed at the start of every $1 line. Next, $4 is split on the > (greater then) as array b. I am not sure how to account for the two other possibilities in $4 so the correct output is printed. Every... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. UNIX for Advanced & Expert Users

Support for Unicode in GTK2 and GTK3 file selection box?

I'm on Tiny Core Linux Pure64 10.1. My locale is en_US.UTF-8 and I generally have no trouble with Unicode characters with one exception: When I try to use Unicode characters in GTK applications' file selection box, I get "Invalid file name": http://files.dantas.airpost.net/public/save_file.jpg ... (11 Replies)
Discussion started by: DevuanFan
11 Replies
DPM-REGISTER(1) 					    DPM Administrator Commands						   DPM-REGISTER(1)

NAME
dpm-register - register external files in DPNS SYNOPSIS
dpm-register --filesize filesize [ --user owner_user ] [ --group owner_group ] [ --mode filemode ] --pfn pfn --server hostname [ --st sta- tus ] [ --help ] filename DESCRIPTION
dpm-register registers a given filename with the specified permissions into DPNS: - create the file metadata entry in DPNS (dpns_creat) - set the ownership (dpns_chown) to owner_user : owner_group (by default the requester's DN and group) - set the filemode (dpns_chmod) to filemode - set the size of the file (dpns_setfsize) to filesize - add the replica entry (dpns_addreplicax) setting * sfn = pfn * status to status ('O' for Online, 'N' for Nearline) * f_type = 'P' (Permanent) * r_type = 'P' (Primary) EXAMPLE
dpm-register --filesize 525424 --server `hostname --fqdn` --group biomed --pfn dicom:///1/2/3 /dpm/cern.ch/home/biomed/mdm/1/2/3 EXIT STATUS
This program returns 0 if the operation was successful or >0 if the operation failed. SEE ALSO
dpns_creat(3), dpns_chown(3), dpns_chmod(3), dpns_setfsize(3), dpns_addreplicax(3) LCG
$Date: 2008/01/07 10:38:38 $ DPM-REGISTER(1)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy