Splitting file content into the files [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite













This question already has an answer here:



  • splitting file based on values in specific column

    1 answer



  • Splitting file content into other files based on parsed parameter value in file [duplicate]

    1 answer



  • Extract data from a file and place in different files based on1 column value

    5 answers



I have a big huge file e.g



chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300


I need help in splitting the file in multiple files by grouping the first column values e.g



File1.txt



chr1 1 G 300
chr1 2 A 500
chr1 3 C 200


file 3.txt



chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400






share|improve this question













marked as duplicate by Kusalananda shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Apr 20 at 12:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    -1
    down vote

    favorite













    This question already has an answer here:



    • splitting file based on values in specific column

      1 answer



    • Splitting file content into other files based on parsed parameter value in file [duplicate]

      1 answer



    • Extract data from a file and place in different files based on1 column value

      5 answers



    I have a big huge file e.g



    chr1 1 G 300
    chr1 2 A 500
    chr1 3 C 200
    chr4 1 T 35
    chr4 2 G 400
    chr4 3 C 435
    chr3 1 G 300
    chr3 2 A 500
    chr3 3 C 200
    chr3 1 T 35
    chr3 2 G 400
    chr6 3 C 435
    chr6 4 A 223
    chr6 5 T 400
    chr6 6 G 300


    I need help in splitting the file in multiple files by grouping the first column values e.g



    File1.txt



    chr1 1 G 300
    chr1 2 A 500
    chr1 3 C 200


    file 3.txt



    chr3 1 G 300
    chr3 2 A 500
    chr3 3 C 200
    chr3 1 T 35
    chr3 2 G 400






    share|improve this question













    marked as duplicate by Kusalananda shell
    Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Apr 20 at 12:04


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite












      This question already has an answer here:



      • splitting file based on values in specific column

        1 answer



      • Splitting file content into other files based on parsed parameter value in file [duplicate]

        1 answer



      • Extract data from a file and place in different files based on1 column value

        5 answers



      I have a big huge file e.g



      chr1 1 G 300
      chr1 2 A 500
      chr1 3 C 200
      chr4 1 T 35
      chr4 2 G 400
      chr4 3 C 435
      chr3 1 G 300
      chr3 2 A 500
      chr3 3 C 200
      chr3 1 T 35
      chr3 2 G 400
      chr6 3 C 435
      chr6 4 A 223
      chr6 5 T 400
      chr6 6 G 300


      I need help in splitting the file in multiple files by grouping the first column values e.g



      File1.txt



      chr1 1 G 300
      chr1 2 A 500
      chr1 3 C 200


      file 3.txt



      chr3 1 G 300
      chr3 2 A 500
      chr3 3 C 200
      chr3 1 T 35
      chr3 2 G 400






      share|improve this question














      This question already has an answer here:



      • splitting file based on values in specific column

        1 answer



      • Splitting file content into other files based on parsed parameter value in file [duplicate]

        1 answer



      • Extract data from a file and place in different files based on1 column value

        5 answers



      I have a big huge file e.g



      chr1 1 G 300
      chr1 2 A 500
      chr1 3 C 200
      chr4 1 T 35
      chr4 2 G 400
      chr4 3 C 435
      chr3 1 G 300
      chr3 2 A 500
      chr3 3 C 200
      chr3 1 T 35
      chr3 2 G 400
      chr6 3 C 435
      chr6 4 A 223
      chr6 5 T 400
      chr6 6 G 300


      I need help in splitting the file in multiple files by grouping the first column values e.g



      File1.txt



      chr1 1 G 300
      chr1 2 A 500
      chr1 3 C 200


      file 3.txt



      chr3 1 G 300
      chr3 2 A 500
      chr3 3 C 200
      chr3 1 T 35
      chr3 2 G 400




      This question already has an answer here:



      • splitting file based on values in specific column

        1 answer



      • Splitting file content into other files based on parsed parameter value in file [duplicate]

        1 answer



      • Extract data from a file and place in different files based on1 column value

        5 answers









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 20 at 11:59









      Archemar

      18.9k93366




      18.9k93366









      asked Apr 20 at 11:44









      sidd

      1




      1




      marked as duplicate by Kusalananda shell
      Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Apr 20 at 12:04


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Kusalananda shell
      Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Apr 20 at 12:04


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Awk solution:



          awk ' print > ("file" substr($1, 4) ".txt") ' file



          • substr($1, 4) - extract substring from the 1st field value $1 starting from position 4

          Viewing results:



          $ head file[0-9]*.txt
          ==> file1.txt <==
          chr1 1 G 300
          chr1 2 A 500
          chr1 3 C 200

          ==> file3.txt <==
          chr3 1 G 300
          chr3 2 A 500
          chr3 3 C 200
          chr3 1 T 35
          chr3 2 G 400

          ==> file4.txt <==
          chr4 1 T 35
          chr4 2 G 400
          chr4 3 C 435

          ==> file6.txt <==
          chr6 3 C 435
          chr6 4 A 223
          chr6 5 T 400
          chr6 6 G 300





          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Awk solution:



            awk ' print > ("file" substr($1, 4) ".txt") ' file



            • substr($1, 4) - extract substring from the 1st field value $1 starting from position 4

            Viewing results:



            $ head file[0-9]*.txt
            ==> file1.txt <==
            chr1 1 G 300
            chr1 2 A 500
            chr1 3 C 200

            ==> file3.txt <==
            chr3 1 G 300
            chr3 2 A 500
            chr3 3 C 200
            chr3 1 T 35
            chr3 2 G 400

            ==> file4.txt <==
            chr4 1 T 35
            chr4 2 G 400
            chr4 3 C 435

            ==> file6.txt <==
            chr6 3 C 435
            chr6 4 A 223
            chr6 5 T 400
            chr6 6 G 300





            share|improve this answer

























              up vote
              2
              down vote













              Awk solution:



              awk ' print > ("file" substr($1, 4) ".txt") ' file



              • substr($1, 4) - extract substring from the 1st field value $1 starting from position 4

              Viewing results:



              $ head file[0-9]*.txt
              ==> file1.txt <==
              chr1 1 G 300
              chr1 2 A 500
              chr1 3 C 200

              ==> file3.txt <==
              chr3 1 G 300
              chr3 2 A 500
              chr3 3 C 200
              chr3 1 T 35
              chr3 2 G 400

              ==> file4.txt <==
              chr4 1 T 35
              chr4 2 G 400
              chr4 3 C 435

              ==> file6.txt <==
              chr6 3 C 435
              chr6 4 A 223
              chr6 5 T 400
              chr6 6 G 300





              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                Awk solution:



                awk ' print > ("file" substr($1, 4) ".txt") ' file



                • substr($1, 4) - extract substring from the 1st field value $1 starting from position 4

                Viewing results:



                $ head file[0-9]*.txt
                ==> file1.txt <==
                chr1 1 G 300
                chr1 2 A 500
                chr1 3 C 200

                ==> file3.txt <==
                chr3 1 G 300
                chr3 2 A 500
                chr3 3 C 200
                chr3 1 T 35
                chr3 2 G 400

                ==> file4.txt <==
                chr4 1 T 35
                chr4 2 G 400
                chr4 3 C 435

                ==> file6.txt <==
                chr6 3 C 435
                chr6 4 A 223
                chr6 5 T 400
                chr6 6 G 300





                share|improve this answer













                Awk solution:



                awk ' print > ("file" substr($1, 4) ".txt") ' file



                • substr($1, 4) - extract substring from the 1st field value $1 starting from position 4

                Viewing results:



                $ head file[0-9]*.txt
                ==> file1.txt <==
                chr1 1 G 300
                chr1 2 A 500
                chr1 3 C 200

                ==> file3.txt <==
                chr3 1 G 300
                chr3 2 A 500
                chr3 3 C 200
                chr3 1 T 35
                chr3 2 G 400

                ==> file4.txt <==
                chr4 1 T 35
                chr4 2 G 400
                chr4 3 C 435

                ==> file6.txt <==
                chr6 3 C 435
                chr6 4 A 223
                chr6 5 T 400
                chr6 6 G 300






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Apr 20 at 12:01









                RomanPerekhrest

                22.4k12144




                22.4k12144












                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)