0

I have a script that creates a large number of lines.

After, let's say, 10000 lines, I need it to move the text file to another name automatically. I can't seem to figure it out, but I guess using "While" "wc" and "mv" might make it possible.

I would like to put it in my bash script, so if the text file is at or over 10000 lines, it will move to list1 then when that list reaches 10000, it will move to list2, etc.

Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
  • 3
    [split](http://stackoverflow.com/questions/7764755/unix-how-to-split-a-file-into-equal-parts-without-breaking-individual-lines) can break lines from standard input. – cesarse Jul 25 '13 at 20:38
  • Are you intending to pipe the first script or the file generated by the first script is independent? If piping you could do something like this thread http://stackoverflow.com/questions/7290546/bash-script-looping-over-line-input – Caian Jul 25 '13 at 20:48

1 Answers1

0

maybe something like this:

#!/bin/bash

while [ 1 == 1 ]
do
     NUMLINES=`wc -l < path_to_file`
     if [ "$NUMLINES" -gt 10000 ]; then
        cat path_to_file >> path_to_backup_file_1
        rm path_to_file
        NUMLINES=`wc -l < path_to_backup_file_1`
        if [ "$NUMLINES" -gt 10000 ]; then
           cat path_to_backup_file_1 >> path_to_backup_file_2
           rm path_to_backup_file_1
        fi
     fi
     sleep 10
done
~
ja_mesa
  • 1,971
  • 1
  • 11
  • 7