-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.

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.

  • I JUST NEED TO RENAME FILES LIKE ABC.TXT?? TO OUTPUT_1 AND HOW TO DO FOR 5 OUTPUT FILES LIKE THIS – Shivani Jan 11 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 Jan 11 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 Jan 11 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 Jan 11 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 Jan 11 at 20:49

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.