print multiple words separated by space
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a text file and the data inside has format like (name age country):
michael jordans 25 US
adam smith 30 UK
chris wood ABC 22 Aus
if I use command: cat text.txt | awk 'print $1'
--> it will print:
michael
adam
chris
but I want to print the full name:
michael jordans
adam smith
chris wood ABC
so please help me this, which command should I use ?
If we need, we can change the format data like:
michael jordans|25|US
adam smith|30|UK
chris wood ABC|22|Aus
text-processing awk printf
add a comment |Â
up vote
1
down vote
favorite
I have a text file and the data inside has format like (name age country):
michael jordans 25 US
adam smith 30 UK
chris wood ABC 22 Aus
if I use command: cat text.txt | awk 'print $1'
--> it will print:
michael
adam
chris
but I want to print the full name:
michael jordans
adam smith
chris wood ABC
so please help me this, which command should I use ?
If we need, we can change the format data like:
michael jordans|25|US
adam smith|30|UK
chris wood ABC|22|Aus
text-processing awk printf
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a text file and the data inside has format like (name age country):
michael jordans 25 US
adam smith 30 UK
chris wood ABC 22 Aus
if I use command: cat text.txt | awk 'print $1'
--> it will print:
michael
adam
chris
but I want to print the full name:
michael jordans
adam smith
chris wood ABC
so please help me this, which command should I use ?
If we need, we can change the format data like:
michael jordans|25|US
adam smith|30|UK
chris wood ABC|22|Aus
text-processing awk printf
I have a text file and the data inside has format like (name age country):
michael jordans 25 US
adam smith 30 UK
chris wood ABC 22 Aus
if I use command: cat text.txt | awk 'print $1'
--> it will print:
michael
adam
chris
but I want to print the full name:
michael jordans
adam smith
chris wood ABC
so please help me this, which command should I use ?
If we need, we can change the format data like:
michael jordans|25|US
adam smith|30|UK
chris wood ABC|22|Aus
text-processing awk printf
text-processing awk printf
edited Sep 22 at 12:13
Jeff Schaller
33.3k849111
33.3k849111
asked Jun 15 '16 at 3:31
user175124
61
61
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
sed 's/^([^0-9]*).*/1/' text.tex
This assumes that the name does not contain a numeric character and the field just after the name starts with a number.
When you separate the fields by |
, it can be done by
sed 's/^([^|]*).*/1/' text.tex
or if you like awk, you can do
awk -F| 'print $1' text.tex
add a comment |Â
up vote
0
down vote
If you change the file to have proper field separators, like |
, the solution is trivial:
awk -F'|' 'print $1' input_file
If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:
awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
sed 's/^([^0-9]*).*/1/' text.tex
This assumes that the name does not contain a numeric character and the field just after the name starts with a number.
When you separate the fields by |
, it can be done by
sed 's/^([^|]*).*/1/' text.tex
or if you like awk, you can do
awk -F| 'print $1' text.tex
add a comment |Â
up vote
1
down vote
sed 's/^([^0-9]*).*/1/' text.tex
This assumes that the name does not contain a numeric character and the field just after the name starts with a number.
When you separate the fields by |
, it can be done by
sed 's/^([^|]*).*/1/' text.tex
or if you like awk, you can do
awk -F| 'print $1' text.tex
add a comment |Â
up vote
1
down vote
up vote
1
down vote
sed 's/^([^0-9]*).*/1/' text.tex
This assumes that the name does not contain a numeric character and the field just after the name starts with a number.
When you separate the fields by |
, it can be done by
sed 's/^([^|]*).*/1/' text.tex
or if you like awk, you can do
awk -F| 'print $1' text.tex
sed 's/^([^0-9]*).*/1/' text.tex
This assumes that the name does not contain a numeric character and the field just after the name starts with a number.
When you separate the fields by |
, it can be done by
sed 's/^([^|]*).*/1/' text.tex
or if you like awk, you can do
awk -F| 'print $1' text.tex
edited Jun 15 '16 at 3:49
answered Jun 15 '16 at 3:43
unxnut
3,4202918
3,4202918
add a comment |Â
add a comment |Â
up vote
0
down vote
If you change the file to have proper field separators, like |
, the solution is trivial:
awk -F'|' 'print $1' input_file
If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:
awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file
add a comment |Â
up vote
0
down vote
If you change the file to have proper field separators, like |
, the solution is trivial:
awk -F'|' 'print $1' input_file
If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:
awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you change the file to have proper field separators, like |
, the solution is trivial:
awk -F'|' 'print $1' input_file
If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:
awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file
If you change the file to have proper field separators, like |
, the solution is trivial:
awk -F'|' 'print $1' input_file
If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:
awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file
answered Jun 15 '16 at 5:51
Michael Vehrs
2,18037
2,18037
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f289811%2fprint-multiple-words-separated-by-space%23new-answer', 'question_page');
);
Post as a guest
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
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
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