Reputation: 25
I have a .TXT file containing account numbers. Sample: TRV001 TRV002 TRV003 TRV004... The values are separated by space. I want to split this file containing first 1000 account numbers in one file and next 1000 accounts in the next file using bash.These account numbers are coming from a report so we don't know how many account number are we going to get in the file.
Upvotes: 0
Views: 82
Reputation: 25
Thanks all for help, I was able to work it out. I changed the format of the file to have only one account number per line of the file and then used split -l 1000 to split the files.
Upvotes: 0
Reputation: 12877
Assuming the source file is called acc, you can use awk piped through to split
awk '{ for (i=1;i<=NF;i++) { print $i } }' acc | split -l 1000
For field in each line, print the field on a separate line using awk and then put the output in separate files (default prefix x) using split
Upvotes: 1