How can i get first word form a line.
for eg.
I have this line:
"nbs2yth 3123 1 fsfsa thisissamletext"
I want to store the first word(here "nbs2yth") in a variable.
How can i do this, either using grep or awk commmand.
How can i get first word form a line.
for eg.
I have this line:
"nbs2yth 3123 1 fsfsa thisissamletext"
I want to store the first word(here "nbs2yth") in a variable.
How can i do this, either using grep or awk commmand.
with bash
# aline="n=nbs2yth 3123 1 fsfsa thisissamletext"
# set -- $aline
# echo $1
nbs2yth
with awk
echo "$aline" | awk '{print $1}'
To strip out the first space till the end:
var=${string%% *}
Regards
var1="nbs2yth 3123 1 fsfsa thisissamletext"
echo $var1 | awk -F" " '{print $1}'
no need -F" "
You are correct, no need to give -F" ", as the default delimiter for awk command is "<space>". But it is always better practice to use -F" " to specify the delimiter what we are passing...
-regards.
not just space.