-2

I have output files from split called

shivi11aa
shivi11ab

(etc.)

How may I rename these existing files as

output_1
output_2

(etc.)

If I have 1000 files, the last one should be output_1000.

9
  • 1
    I edited the question based on some of your comments. You should have been able to do this yourself though, by pressing the edit link under the question. Please edit it further if it's not correct.
    – Kusalananda
    Commented Jan 11, 2019 at 21:07
  • thanks,but n depends on the number of my ouput files
    – Shivani
    Commented Jan 11, 2019 at 21:11
  • 1
    thank you very much and heartily thankfull
    – Shivani
    Commented Jan 11, 2019 at 21:14
  • 1
    @Shivani Please also read What should I do when someone answers my question?. No need to hurry, though. Just take your time.
    – PerlDuck
    Commented Jan 11, 2019 at 21:20
  • 1
    Also, for future reference, see this very nice writeup by Jeff, another user here: unix.meta.stackexchange.com/questions/5015
    – Kusalananda
    Commented Jan 11, 2019 at 21:21

1 Answer 1

5
n=0
for filename in shivi11*; do
    n=$(( n + 1 ))
    mv -i "$filename" "output_$n"
done

... where shivi11* is a pattern that must match all files that you'd like to rename (and nothing else).

Back up your data and test this.


Answer to the original question (before editing it):

If you by "split" mean the split utility, then you may invoke the utility like this to get what you want (this assumes GNU split and that you'd like to split the file file into 20 KB bits):

split -b 20k -a 1 --numeric-suffixes=1 file output_

This creates output_1, output_2 etc.

Note that since we restrict the suffix length to a single character with -a 1, this would not be able to split into more than 9 files. Using e.g. -a 2 would create files named output_01, output_02 etc. up to and including output_99, but not output_100.

The --numeric-suffixes=1 option is a GNU split-specific option that selects numeric suffixes starting at the given number (instead of at 0 as using -d would do). Normally, split creates files with alphabetic suffixes.

15
  • I JUST NEED TO RENAME FILES LIKE ABC.TXT?? TO OUTPUT_1 AND HOW TO DO FOR 5 OUTPUT FILES LIKE THIS
    – Shivani
    Commented Jan 11, 2019 at 20:40
  • 2
    @Shivani No need to shout. Calmly make your question unambiguous instead. If you don't use the split utility, then don't mention it (which you do now with "the output from split"). Instead tell us what you have and what you want, and someone may be interested enough to answer.
    – Kusalananda
    Commented Jan 11, 2019 at 20:43
  • MY QUESTION IS TO RENAME THE MULTIPLE FILES LIKE ABC.TXT TO OUTPUT_1,OUTPUT_2 AND SO ON IF I HAVE FIVE OUTPUT FILES,,PLEASE SHARE HOW TO USE MOVE COMMAND BY USING FOR LOOP IN THIS
    – Shivani
    Commented Jan 11, 2019 at 20:45
  • 4
    @Shivani Unstick you CapsLock key and update your question. Also note that we are volunteers and that this is not a code-writing service.
    – Kusalananda
    Commented Jan 11, 2019 at 20:47
  • my question is to rename the multiple files like abc.txt to ouput_1,output_2 and so on if i have five output files.How to use for loop for renaming.Actually i already split the files according to lines and now i want to rename them
    – Shivani
    Commented Jan 11, 2019 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .