Deleting first column with vimHow to delete second column in Vim?Reformatting tablesawk repeats lines too many timesGet rid of the sequence No. on the first columnAdd column to text file where the value is the row number?Removing duplicate rows based on column valueHow to extract multiple bits of information that appear on different lines within the same text fileHow can I replace three columns 'XXX' with the number?removing the last repeated lines in the text filesSorting each column and getting their corresponding key IDs in the first row for the bottom 2 values

Why didn't he give Sam the antidote?

Does the Flixbus N770 from Antwerp to Copenhagen go by ferry to Denmark

Over powered shield?

Is cloning illegal in the Star Trek: TNG continuity?

Does permanent loss of castling rights reset three fold repetition

Injection from two strings to one string

How long could a human survive completely without the immune system?

What cluster of stars is this with a "dark donut" to one side?

Self-learning Calculus. Where does Lang's First Course in Calculus stay when compared to Apostol/Spivak/Courant

Are great composers almost always prodigious performers?

Why is there "Il" in "Il mio tesoro intanto"?

How to be productive while waiting for meetings to start, when managers are casual about being late

Find the percentage

A sentient carnivorous species trying to preserve life. How could they find a new food source?

Concrete description of lift in Arens-Eells space

How do I break the broom in Untitled Goose Game?

Minimum number of MPs

3x3 self-descriptive squares

Can I bring alcohol to Dubai?

how do you value what your leisure time is worth?

How stable are PID loops really?

How acceptable is an ellipsis "..." in formal mathematics?

Why does allocating a single 2D array take longer than a loop allocating multiple 1D arrays of the same total size and shape?

I am measuring a 9W LED with a clamp on ammeter. Why does it only draw 7.62W?



Deleting first column with vim


How to delete second column in Vim?Reformatting tablesawk repeats lines too many timesGet rid of the sequence No. on the first columnAdd column to text file where the value is the row number?Removing duplicate rows based on column valueHow to extract multiple bits of information that appear on different lines within the same text fileHow can I replace three columns 'XXX' with the number?removing the last repeated lines in the text filesSorting each column and getting their corresponding key IDs in the first row for the bottom 2 values






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









7















I have a text file.



number 1_1 t number1_2 t etc
number 2_1 t number2_2 t etc


I want to remove the first column of this file (corresponding to number1_1, number2_1 etc, ie the numbers before the first tab for each row). I read this post that proposes a solution to delete the first column (see Peter's answer). However, it doesn't work for me as the numbers have different sizes and I cannot repeat the operation to delete the first column. How can I do then?










share|improve this question


























  • Do you want a vim specific solution?

    – jobin
    May 26 '14 at 9:48











  • preferably, but not necessarily (what else do you propose?)

    – bigTree
    May 26 '14 at 9:48











  • @bigTree do you want command line answers?

    – Avinash Raj
    May 26 '14 at 10:00






  • 1





    @AvinashRaj Command line answers would be good thanks

    – bigTree
    May 26 '14 at 10:04

















7















I have a text file.



number 1_1 t number1_2 t etc
number 2_1 t number2_2 t etc


I want to remove the first column of this file (corresponding to number1_1, number2_1 etc, ie the numbers before the first tab for each row). I read this post that proposes a solution to delete the first column (see Peter's answer). However, it doesn't work for me as the numbers have different sizes and I cannot repeat the operation to delete the first column. How can I do then?










share|improve this question


























  • Do you want a vim specific solution?

    – jobin
    May 26 '14 at 9:48











  • preferably, but not necessarily (what else do you propose?)

    – bigTree
    May 26 '14 at 9:48











  • @bigTree do you want command line answers?

    – Avinash Raj
    May 26 '14 at 10:00






  • 1





    @AvinashRaj Command line answers would be good thanks

    – bigTree
    May 26 '14 at 10:04













7












7








7


2






I have a text file.



number 1_1 t number1_2 t etc
number 2_1 t number2_2 t etc


I want to remove the first column of this file (corresponding to number1_1, number2_1 etc, ie the numbers before the first tab for each row). I read this post that proposes a solution to delete the first column (see Peter's answer). However, it doesn't work for me as the numbers have different sizes and I cannot repeat the operation to delete the first column. How can I do then?










share|improve this question
















I have a text file.



number 1_1 t number1_2 t etc
number 2_1 t number2_2 t etc


I want to remove the first column of this file (corresponding to number1_1, number2_1 etc, ie the numbers before the first tab for each row). I read this post that proposes a solution to delete the first column (see Peter's answer). However, it doesn't work for me as the numbers have different sizes and I cannot repeat the operation to delete the first column. How can I do then?







command-line vim text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:39









Community♦

1




1










asked May 26 '14 at 9:41









bigTreebigTree

2723 gold badges5 silver badges13 bronze badges




2723 gold badges5 silver badges13 bronze badges















  • Do you want a vim specific solution?

    – jobin
    May 26 '14 at 9:48











  • preferably, but not necessarily (what else do you propose?)

    – bigTree
    May 26 '14 at 9:48











  • @bigTree do you want command line answers?

    – Avinash Raj
    May 26 '14 at 10:00






  • 1





    @AvinashRaj Command line answers would be good thanks

    – bigTree
    May 26 '14 at 10:04

















  • Do you want a vim specific solution?

    – jobin
    May 26 '14 at 9:48











  • preferably, but not necessarily (what else do you propose?)

    – bigTree
    May 26 '14 at 9:48











  • @bigTree do you want command line answers?

    – Avinash Raj
    May 26 '14 at 10:00






  • 1





    @AvinashRaj Command line answers would be good thanks

    – bigTree
    May 26 '14 at 10:04
















Do you want a vim specific solution?

– jobin
May 26 '14 at 9:48





Do you want a vim specific solution?

– jobin
May 26 '14 at 9:48













preferably, but not necessarily (what else do you propose?)

– bigTree
May 26 '14 at 9:48





preferably, but not necessarily (what else do you propose?)

– bigTree
May 26 '14 at 9:48













@bigTree do you want command line answers?

– Avinash Raj
May 26 '14 at 10:00





@bigTree do you want command line answers?

– Avinash Raj
May 26 '14 at 10:00




1




1





@AvinashRaj Command line answers would be good thanks

– bigTree
May 26 '14 at 10:04





@AvinashRaj Command line answers would be good thanks

– bigTree
May 26 '14 at 10:04










5 Answers
5






active

oldest

votes


















6
















This should delete all chars before and including the 1st tab on any line:



:%s/^[^t]*t//



Command line cut:



cut -f 2- filename.txt > filenamenew.txt


cut defaults to tabs; if you want something else like a space add -d " ".
-f is fields to copy over. 2- means all from (and including) column 2.






share|improve this answer


































    4
















    Through awk,



    awk -F"t" 'print FS,$2' file > newfile


    It cuts the first column and prints only the remaining tab and second column.



    Through sed,



    sed -r 's/^([^t]*)t(.*)$/t2/g' file > newfile





    share|improve this answer



























    • see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

      – Avinash Raj
      May 26 '14 at 13:58


















    3
















    In Vi to remove first column (separated by space), you can do:



    :%norm dW


    for a column separated by Tab, it's:



    :%norm dfCtrl+VTab



    So the command which would remove the first column from file (in-place) can be:



    ex +"%norm df$(echo -e 't')" -scwq file


    To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.



    Or based on Chris suggestion, like:



    ex -c':exe ":%norm df<Tab>"' -sc'%p|q!' <(echo -e "a atb btc c")



    Alternatively do it in visual mode (if starting from the top-left):



    1. Enter visual-block by Ctrl+v.

    2. Jump at the end and select first column by pressing: G, E (or adjust manually).

    3. Press d to delete the selected block.





    share|improve this answer


































      3
















      :%s/[^t]*t//



      On every line (%), replace (s/ORIGINAL/REPLACEMENT/) the first occurrence of “non-tab characters ([^t], in any number (*)) followed by a tab t” by nothing. You can type Tab instead of t.



      Alternatively you can match the shortest sequence of characters (.-) ending in a tab. .*t would match the longest match for .*, so it would match all but the last column; .- matches the shortest match which is the first column.



      :%s/.-t//






      share|improve this answer


































        0
















        To remove the remaining space before the second column I suggest:



        :%norm dfCtrl+VTabx






        share|improve this answer


























          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f472332%2fdeleting-first-column-with-vim%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6
















          This should delete all chars before and including the 1st tab on any line:



          :%s/^[^t]*t//



          Command line cut:



          cut -f 2- filename.txt > filenamenew.txt


          cut defaults to tabs; if you want something else like a space add -d " ".
          -f is fields to copy over. 2- means all from (and including) column 2.






          share|improve this answer































            6
















            This should delete all chars before and including the 1st tab on any line:



            :%s/^[^t]*t//



            Command line cut:



            cut -f 2- filename.txt > filenamenew.txt


            cut defaults to tabs; if you want something else like a space add -d " ".
            -f is fields to copy over. 2- means all from (and including) column 2.






            share|improve this answer





























              6














              6










              6









              This should delete all chars before and including the 1st tab on any line:



              :%s/^[^t]*t//



              Command line cut:



              cut -f 2- filename.txt > filenamenew.txt


              cut defaults to tabs; if you want something else like a space add -d " ".
              -f is fields to copy over. 2- means all from (and including) column 2.






              share|improve this answer















              This should delete all chars before and including the 1st tab on any line:



              :%s/^[^t]*t//



              Command line cut:



              cut -f 2- filename.txt > filenamenew.txt


              cut defaults to tabs; if you want something else like a space add -d " ".
              -f is fields to copy over. 2- means all from (and including) column 2.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 26 '14 at 15:53









              Community♦

              1




              1










              answered May 26 '14 at 9:56









              RinzwindRinzwind

              223k29 gold badges430 silver badges573 bronze badges




              223k29 gold badges430 silver badges573 bronze badges


























                  4
















                  Through awk,



                  awk -F"t" 'print FS,$2' file > newfile


                  It cuts the first column and prints only the remaining tab and second column.



                  Through sed,



                  sed -r 's/^([^t]*)t(.*)$/t2/g' file > newfile





                  share|improve this answer



























                  • see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                    – Avinash Raj
                    May 26 '14 at 13:58















                  4
















                  Through awk,



                  awk -F"t" 'print FS,$2' file > newfile


                  It cuts the first column and prints only the remaining tab and second column.



                  Through sed,



                  sed -r 's/^([^t]*)t(.*)$/t2/g' file > newfile





                  share|improve this answer



























                  • see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                    – Avinash Raj
                    May 26 '14 at 13:58













                  4














                  4










                  4









                  Through awk,



                  awk -F"t" 'print FS,$2' file > newfile


                  It cuts the first column and prints only the remaining tab and second column.



                  Through sed,



                  sed -r 's/^([^t]*)t(.*)$/t2/g' file > newfile





                  share|improve this answer















                  Through awk,



                  awk -F"t" 'print FS,$2' file > newfile


                  It cuts the first column and prints only the remaining tab and second column.



                  Through sed,



                  sed -r 's/^([^t]*)t(.*)$/t2/g' file > newfile






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 26 '14 at 10:12

























                  answered May 26 '14 at 10:05









                  Avinash RajAvinash Raj

                  55.4k44 gold badges177 silver badges227 bronze badges




                  55.4k44 gold badges177 silver badges227 bronze badges















                  • see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                    – Avinash Raj
                    May 26 '14 at 13:58

















                  • see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                    – Avinash Raj
                    May 26 '14 at 13:58
















                  see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                  – Avinash Raj
                  May 26 '14 at 13:58





                  see askubuntu.com/questions/472332/deleting-first-column-with-vim/…

                  – Avinash Raj
                  May 26 '14 at 13:58











                  3
















                  In Vi to remove first column (separated by space), you can do:



                  :%norm dW


                  for a column separated by Tab, it's:



                  :%norm dfCtrl+VTab



                  So the command which would remove the first column from file (in-place) can be:



                  ex +"%norm df$(echo -e 't')" -scwq file


                  To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.



                  Or based on Chris suggestion, like:



                  ex -c':exe ":%norm df<Tab>"' -sc'%p|q!' <(echo -e "a atb btc c")



                  Alternatively do it in visual mode (if starting from the top-left):



                  1. Enter visual-block by Ctrl+v.

                  2. Jump at the end and select first column by pressing: G, E (or adjust manually).

                  3. Press d to delete the selected block.





                  share|improve this answer































                    3
















                    In Vi to remove first column (separated by space), you can do:



                    :%norm dW


                    for a column separated by Tab, it's:



                    :%norm dfCtrl+VTab



                    So the command which would remove the first column from file (in-place) can be:



                    ex +"%norm df$(echo -e 't')" -scwq file


                    To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.



                    Or based on Chris suggestion, like:



                    ex -c':exe ":%norm df<Tab>"' -sc'%p|q!' <(echo -e "a atb btc c")



                    Alternatively do it in visual mode (if starting from the top-left):



                    1. Enter visual-block by Ctrl+v.

                    2. Jump at the end and select first column by pressing: G, E (or adjust manually).

                    3. Press d to delete the selected block.





                    share|improve this answer





























                      3














                      3










                      3









                      In Vi to remove first column (separated by space), you can do:



                      :%norm dW


                      for a column separated by Tab, it's:



                      :%norm dfCtrl+VTab



                      So the command which would remove the first column from file (in-place) can be:



                      ex +"%norm df$(echo -e 't')" -scwq file


                      To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.



                      Or based on Chris suggestion, like:



                      ex -c':exe ":%norm df<Tab>"' -sc'%p|q!' <(echo -e "a atb btc c")



                      Alternatively do it in visual mode (if starting from the top-left):



                      1. Enter visual-block by Ctrl+v.

                      2. Jump at the end and select first column by pressing: G, E (or adjust manually).

                      3. Press d to delete the selected block.





                      share|improve this answer















                      In Vi to remove first column (separated by space), you can do:



                      :%norm dW


                      for a column separated by Tab, it's:



                      :%norm dfCtrl+VTab



                      So the command which would remove the first column from file (in-place) can be:



                      ex +"%norm df$(echo -e 't')" -scwq file


                      To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.



                      Or based on Chris suggestion, like:



                      ex -c':exe ":%norm df<Tab>"' -sc'%p|q!' <(echo -e "a atb btc c")



                      Alternatively do it in visual mode (if starting from the top-left):



                      1. Enter visual-block by Ctrl+v.

                      2. Jump at the end and select first column by pressing: G, E (or adjust manually).

                      3. Press d to delete the selected block.






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Apr 13 '17 at 12:51









                      Community♦

                      1




                      1










                      answered Oct 16 '15 at 14:11









                      kenorbkenorb

                      5,4821 gold badge45 silver badges67 bronze badges




                      5,4821 gold badge45 silver badges67 bronze badges
























                          3
















                          :%s/[^t]*t//



                          On every line (%), replace (s/ORIGINAL/REPLACEMENT/) the first occurrence of “non-tab characters ([^t], in any number (*)) followed by a tab t” by nothing. You can type Tab instead of t.



                          Alternatively you can match the shortest sequence of characters (.-) ending in a tab. .*t would match the longest match for .*, so it would match all but the last column; .- matches the shortest match which is the first column.



                          :%s/.-t//






                          share|improve this answer































                            3
















                            :%s/[^t]*t//



                            On every line (%), replace (s/ORIGINAL/REPLACEMENT/) the first occurrence of “non-tab characters ([^t], in any number (*)) followed by a tab t” by nothing. You can type Tab instead of t.



                            Alternatively you can match the shortest sequence of characters (.-) ending in a tab. .*t would match the longest match for .*, so it would match all but the last column; .- matches the shortest match which is the first column.



                            :%s/.-t//






                            share|improve this answer





























                              3














                              3










                              3









                              :%s/[^t]*t//



                              On every line (%), replace (s/ORIGINAL/REPLACEMENT/) the first occurrence of “non-tab characters ([^t], in any number (*)) followed by a tab t” by nothing. You can type Tab instead of t.



                              Alternatively you can match the shortest sequence of characters (.-) ending in a tab. .*t would match the longest match for .*, so it would match all but the last column; .- matches the shortest match which is the first column.



                              :%s/.-t//






                              share|improve this answer















                              :%s/[^t]*t//



                              On every line (%), replace (s/ORIGINAL/REPLACEMENT/) the first occurrence of “non-tab characters ([^t], in any number (*)) followed by a tab t” by nothing. You can type Tab instead of t.



                              Alternatively you can match the shortest sequence of characters (.-) ending in a tab. .*t would match the longest match for .*, so it would match all but the last column; .- matches the shortest match which is the first column.



                              :%s/.-t//







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Apr 17 at 12:49

























                              answered May 26 '14 at 16:52









                              GillesGilles

                              47.7k13 gold badges107 silver badges145 bronze badges




                              47.7k13 gold badges107 silver badges145 bronze badges
























                                  0
















                                  To remove the remaining space before the second column I suggest:



                                  :%norm dfCtrl+VTabx






                                  share|improve this answer





























                                    0
















                                    To remove the remaining space before the second column I suggest:



                                    :%norm dfCtrl+VTabx






                                    share|improve this answer



























                                      0














                                      0










                                      0









                                      To remove the remaining space before the second column I suggest:



                                      :%norm dfCtrl+VTabx






                                      share|improve this answer













                                      To remove the remaining space before the second column I suggest:



                                      :%norm dfCtrl+VTabx







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 16 '16 at 10:35









                                      SergioAraujoSergioAraujo

                                      3792 silver badges6 bronze badges




                                      3792 silver badges6 bronze badges































                                          draft saved

                                          draft discarded















































                                          Thanks for contributing an answer to Ask Ubuntu!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid …


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f472332%2fdeleting-first-column-with-vim%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

                                          Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?

                                          apt-get update fails to fetch files, “Temporary failure resolving …” errorWhy does apt-get fail to resolve the mirror?Apt-get update not working in Ubuntu 16.04 “temporary failure resolving”Ubuntu 16.04 Server updates - Temporary failure resolving 'ro.archive.ubuntu.com'“Failed to fetch… Temporary failure resolving…” when trying to installTemporary failure resolving ca.archive.ubuntu.comUbuntu 18.04 sudo apt update doesn't work (Failed to Fetch)apt-get error: “Temporary failure resolving 'archive.ubuntu.com' ”“Temporary failure resolving us.archive.ubuntu.com” Live USB rescueTemporary failure resolving 'es.archive.ubuntu.com' on Ubuntu Server15.04 Server fails to update with failed to fetch temporary failure resolving errorsCan't install software from Software CenterApt-get failed to fetch from Ubuntu server with error code 404“Unable to connect” error with apt-get: possible proxy?v12.10 can't apt-get update111: Connection refused when trying apt updateSudo apt-get update