<p>I have a rather large file (150 million lines of 10 chars). I need to split it in 150 files of 2 million lines, with each output line being alternatively the first 5 characters or the last 5 characters of the source line.
I could do this in Perl rather quickly, but I was wondering if there was an easy solution using bash.
Any ideas?</p>

[{'answer_id': 63941, 'author': 'HD.', 'author_id': 6525, 'author_profile': 'https://Stackoverflow.com/users/6525', 'pm_score': 3, 'selected': True, 'text': "<p>Homework?  :-)</p>\n\n<p>I would think that a simple pipe with sed (to split each line into two) and split (to split things up into multiple files) would be enough.</p>\n\n<p>The man command is your friend.</p>\n\n<hr>\n\n<p>Added after confirmation that it is not homework:</p>\n\n<p>How about</p>\n\n<pre><code>sed 's/\\(.....\\)\\(.....\\)/\\1\\n\\2/' input_file | split -l 2000000 - out-prefix-\n</code></pre>\n\n<p>?</p>\n"}, {'answer_id': 63973, 'author': 'che', 'author_id': 7806, 'author_profile': 'https://Stackoverflow.com/users/7806', 'pm_score': 0, 'selected': False, 'text': '<p>I think that something like this could work:</p>\n\n<pre><code>out_file=1\nout_pairs=0\ncat $in_file | while read line; do\n    if [ $out_pairs -gt 1000000 ]; then\n        out_file=$(($out_file + 1))\n        out_pairs=0\n    fi\n    echo "${line%?????}" &gt;&gt; out${out_file}\n    echo "${line#?????}" &gt;&gt; out${out_file}\n    out_pairs=$(($out_pairs + 1))\ndone\n</code></pre>\n\n<p>Not sure if it\'s simpler or more efficient than using Perl, though.</p>\n'}, {'answer_id': 64008, 'author': 'Troels Arvin', 'author_id': 4462, 'author_profile': 'https://Stackoverflow.com/users/4462', 'pm_score': 0, 'selected': False, 'text': '<p>First five chars of each line variant, assuming that the large file called x.txt, and assuming it\'s OK to create files in the current directory with names x.txt.* :</p>\n\n<p>split -l 2000000 x.txt x.txt.out &amp;&amp; (for splitfile in x.txt.out*; do outfile="${splitfile}.firstfive"; echo "$splitfile ->  $outfile"; cut -c 1-5 "$splitfile" > "$outfile"; done)</p>\n'}, {'answer_id': 72982898, 'author': 'lacostenycoder', 'author_id': 3625433, 'author_profile': 'https://Stackoverflow.com/users/3625433', 'pm_score': 0, 'selected': False, 'text': '<p>Why not just use native linux <code>split</code> function?</p>\n<pre><code>split -d -l 999999 input_filename\n</code></pre>\n<p>this will output new split files with file names like <code>x00 x01 x02...</code></p>\n<p>for more info see the manual</p>\n<pre><code>man split\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/63870', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7028/']