Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am in directory a. Under directory a there is a fixed directory b. There are d{091....099} directories under the b directory. There are also different *.gz files under this d directory. I need to extract data from these files (filenames) and print them one after the other.

What I have tried:

i have tried this:

Bash
#!/bin/bash

for file in $(find . -name "*.gz"); do
  file=$(basename ${file})
       echo ${file:0:4} | tee -a receiver_ids > log
       echo ${file:16:17} | tee -a doy > log2
       echo ${file:0:100} | tee -a data_record > log3
done
cut -c 1-3 < doy > doy2
cut -c 1-23 < data_record > summary_name


but by doing this, the files are processed in an unordered way. this is what i get from,

cat data_record
ISTA00TUR_R_20190940000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190990000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190970000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190920000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190980000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190960000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190930000_01D_30S_MO.crx.gz
ISTA00TUR_R_20190950000_01D_30S_MO.crx.gz


how can i fix this?
Posted
Updated 24-Nov-22 2:51am
Comments
Richard MacCutchan 24-Nov-22 8:56am    
You need to pipe them through sort if you want them in order.
Member 15627495 24-Nov-22 9:21am    
hello ! maybe this link could help you :
https://serverfault.com/questions/181787/find-command-default-sorting-order

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900