1

I have number of files with following name details..

2007-07-22-2300-11S.NAN___024_ABI___HH_E_SAC

Where:

  • 2007-07-22 is date.
  • 2300-11S is hhmm-sec.
  • NAN___024 is network same for each file (not required in new name).
  • ABI__HH_E is station name with East channel.
  • SAC is extension.

And, I want to rename all files in following same format:

2007.204.23.00.ABI.e

Where:

  • 2007 is year.
  • 204 is julian day (of 07-22).
  • 23.00 is time.
  • ABI is station.
  • e is channel name.
  • Julian Day 204 was in 4713 BCE; I think you meant the ordinal date. In which case, see date +%j—though that gives 203, not 204 for 2007-07-22. Please explain how your "julian day" is calculated. (Do you count all years as leap years or something like that?) – derobert Aug 15 '15 at 5:14
  • Paste the script or one liner, which you have tried so far – neuron Aug 15 '15 at 5:34
1

Assuming you:

  • wanted "1 + Ordinal date" at Position 2.
  • "_"-padded station names.
  • lowercasing of the channel name

Then this should perform the wanted transform.

$ ls
2007-07-22-2300-11S.NAN___024_ABI___HH_E_SAC
$ for i in *; do
    od="$(expr $(date +%j -d "${i:0:10}") + 1 )";
    chn="${i:39:1}";
    sta="$(echo ${i:30:6} | tr -d '_')";
    mv "$i" "${i:0:4}.$od.${i:11:2}.${i:13:2}.$sta.${chn,,}" ;
  done 
$ ls
2007.204.23.00.ABI.e
1

For mass renaming, prename is your friend. In this case:

prename 's/^(\d*)-(\d*-\d*)-(\d*)-.*___\d*_(\w*)___\w*_(\w*)_\w*/$1.$2.$3.$4.$5/' *

(ignoring the Julian date until the respective questions have been clarified).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.