Ubuntu: split file renaming automation



Question:

After I split my file I want to name them like so. How can I automate this?

2048  split -l 500000 10k_edges_sixth_1000.csv   2049  ls -ltr   2050  mv xaa 10k_edges_sixth_1000_pt1.csv   2051  mv xab 10k_edges_sixth_1000_pt2.csv   2052  mv xac 10k_edges_sixth_1000_pt3.csv   2053  mv xad 10k_edges_sixth_1000_pt4.csv   2054  mv xae 10k_edges_sixth_1000_pt5.csv   2055  mv xaf 10k_edges_sixth_1000_pt6.csv   2056  mv xag 10k_edges_sixth_1000_pt7.csv   2057  mv xah 10k_edges_sixth_1000_pt8.csv   2058  mv xai 10k_edges_sixth_1000_pt9.csv  


Solution:1

Solution

This command should work:

split -l 500000 -d --additional-suffix='.csv' 10k_edges_sixth_1000.csv 10k_edges_sixth_1000_pt  

Explanations for flags

  • -l flag: number of lines per output file.

  • -d flag: force the use of numeric suffixes.

  • --additional-suffix flag: adds a user-specified additional suffix to the end of the file name after the numeric suffix (if enabled).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »