I'm hoping to create a .cl script to run in IRAF. I have a list of spectra on which I want to run dispcor. I was wondering if there's an easy way to paste the output file names with incrementing numbers. The lines look like this:

dispcor extracted_ori5_r1.0001.fits calibrated_ori5_r1.0001.fits

I want the output file name to increase (.0001, .0002, etc.). Any help would be greatly appreciated!

  • 2
    So by "paste the output file names," do you mean that you need to paste text to a file, or do you want to actually generate the new files? – Tumbler41 Aug 2 '16 at 19:32
  • I just need to add the "calibrated_ori5_r1.0xxx.fits" to the end of each line in the text file with incrementing numbers. I will then run this cl script in IRAF. – catclark Aug 2 '16 at 19:36

Starting point:

dispcor extracted_ori5_r1.0001.fits calibrated_ori5_r1.0001.fits
  1. Start recording in register a:

  2. Yank the line:

  3. Put it right under the current line:

  4. Move the cursor to the first 0001:

  5. Increment the number:

  6. Move the cursor to the next 0001:

  7. Increment again:

  8. Stop recording:

  9. Play it back 23 times:


In short:



dispcor extracted_ori5_r1.0001.fits calibrated_ori5_r1.0001.fit
dispcor extracted_ori5_r1.0002.fits calibrated_ori5_r1.0002.fit
dispcor extracted_ori5_r1.0003.fits calibrated_ori5_r1.0003.fit
dispcor extracted_ori5_r1.0004.fits calibrated_ori5_r1.0004.fit
dispcor extracted_ori5_r1.0005.fits calibrated_ori5_r1.0005.fit
dispcor extracted_ori5_r1.0006.fits calibrated_ori5_r1.0006.fit
dispcor extracted_ori5_r1.0007.fits calibrated_ori5_r1.0007.fit
dispcor extracted_ori5_r1.0008.fits calibrated_ori5_r1.0008.fit
dispcor extracted_ori5_r1.0009.fits calibrated_ori5_r1.0009.fit
dispcor extracted_ori5_r1.0025.fits calibrated_ori5_r1.0025.fit
  • Need to be a little careful with this. I'm not sure why I'm getting a different result than you, but because of the leading zero's when I do this my <C-a> assumes octal numbers and increments as such. – Tumbler41 Aug 2 '16 at 19:51
  • 2
    @Tumbler41 Try :set nrformats-=octal – James Aug 2 '16 at 20:00
  • 1
    @DJMcMayhem fair enough, but default behavior is to treat it as octal. So reader be wary. – Tumbler41 Aug 2 '16 at 20:07
  • @Tumbler41 this default is going to be changed (or did already with the latest Vim release) – Christian Brabandt Aug 2 '16 at 20:21
  • Yes you probably can. Could you add a sample to your question? – romainl Aug 2 '16 at 21:00

Here is a different solution. Copy the line: yy, paste 23 times: 23p, go to the second line: :2, Move to the 0001: $F1, block select the range you want to be incremented <ctrl>vGh, increment each number sequentially: g<ctrl-a>

This needs a relative recent Vim, something like 7.4.1000 should do it.

Read the help at :h g_Ctrl-A

  • I forgot to mention. I already have a list of the extracted files, and they skip around (i.e. 1, 2, 3, 4, 9, 10, etc.). Is there a way to use the same number that is found at the beginning of the line at the end of the line? – catclark Aug 2 '16 at 20:53
  • @catclark i don't understand the question – Christian Brabandt Aug 3 '16 at 12:01

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.