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;
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
add a comment
|
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
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
add a comment
|
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
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
command-line vim text-processing
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
add a comment
|
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
add a comment
|
5 Answers
5
active
oldest
votes
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.
add a comment
|
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
see askubuntu.com/questions/472332/deleting-first-column-with-vim/…
– Avinash Raj
May 26 '14 at 13:58
add a comment
|
In Vi to remove first column (separated by space), you can do:
:%norm dW
for a column separated by Tab, it's:
:%norm df
Ctrl+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):
- Enter visual-block by Ctrl+v.
- Jump at the end and select first column by pressing: G, E (or adjust manually).
- Press d to delete the selected block.
add a comment
|
:%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//
add a comment
|
To remove the remaining space before the second column I suggest:
:%norm df
Ctrl+VTabx
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment
|
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.
add a comment
|
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.
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.
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
add a comment
|
add a comment
|
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
see askubuntu.com/questions/472332/deleting-first-column-with-vim/…
– Avinash Raj
May 26 '14 at 13:58
add a comment
|
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
see askubuntu.com/questions/472332/deleting-first-column-with-vim/…
– Avinash Raj
May 26 '14 at 13:58
add a comment
|
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
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
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
add a comment
|
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
add a comment
|
In Vi to remove first column (separated by space), you can do:
:%norm dW
for a column separated by Tab, it's:
:%norm df
Ctrl+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):
- Enter visual-block by Ctrl+v.
- Jump at the end and select first column by pressing: G, E (or adjust manually).
- Press d to delete the selected block.
add a comment
|
In Vi to remove first column (separated by space), you can do:
:%norm dW
for a column separated by Tab, it's:
:%norm df
Ctrl+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):
- Enter visual-block by Ctrl+v.
- Jump at the end and select first column by pressing: G, E (or adjust manually).
- Press d to delete the selected block.
add a comment
|
In Vi to remove first column (separated by space), you can do:
:%norm dW
for a column separated by Tab, it's:
:%norm df
Ctrl+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):
- Enter visual-block by Ctrl+v.
- Jump at the end and select first column by pressing: G, E (or adjust manually).
- Press d to delete the selected block.
In Vi to remove first column (separated by space), you can do:
:%norm dW
for a column separated by Tab, it's:
:%norm df
Ctrl+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):
- Enter visual-block by Ctrl+v.
- Jump at the end and select first column by pressing: G, E (or adjust manually).
- Press d to delete the selected block.
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
add a comment
|
add a comment
|
:%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//
add a comment
|
:%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//
add a comment
|
:%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//
:%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//
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
add a comment
|
add a comment
|
To remove the remaining space before the second column I suggest:
:%norm df
Ctrl+VTabx
add a comment
|
To remove the remaining space before the second column I suggest:
:%norm df
Ctrl+VTabx
add a comment
|
To remove the remaining space before the second column I suggest:
:%norm df
Ctrl+VTabx
To remove the remaining space before the second column I suggest:
:%norm df
Ctrl+VTabx
answered Dec 16 '16 at 10:35
SergioAraujoSergioAraujo
3792 silver badges6 bronze badges
3792 silver badges6 bronze badges
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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