Reputation: 2142
I have a text file with several columns separated by tabs, and thousands of lines like this:
Foo Bar [email protected] 01.01.0001 SomeMoreStuff
Now I would like to extract just the e-mail, which is [email protected]
in this case.
What would the easiest way be to delete everything before and after the e-mail using vim
or any other CLI tool?
Upvotes: 0
Views: 94
Reputation: 27641
The following command will print the third column:
cut -f3 file_name
Upvotes: 4
Reputation: 196886
In Vim I would escape the grim prospect of having to come up with a solid substitution by using a simple macro.
First, record the macro:
qq
0
d2f<tab> <-- this is a tab key
f<tab> <-- this is a tab key
D
q
Second, apply the macro from the line below to the end of the buffer:
:+1,$norm @q
Upvotes: 1
Reputation: 195269
using awk;
awk '$0=$3' file
using pure vim
try this line:
:%s/.*\t\([^@]\+@[^\t]\+\).*/\1/
if you are sure the email sits in the 3rd column, you could also try:
:%s/\v([^\t]*\t){2}([^\t]+).*/\2/
or using vim + awk if you like :)
:%!awk '$0=$3'
Upvotes: 1
Reputation: 45670
in bash:
while read -a ARRAY; do echo ${ARRAY[2]}; done < input
perl in awk-mode
perl -lane 'print $F[2]' input
Upvotes: 0
Reputation: 786291
For command line a simple awk will do the job:
awk '{print $3}' inFile
Upvotes: 1