Separate by more than whitespace.

This is my file

.........hostname.............this is hostname
.........alias...................alias name

Remark use dot(.) instead of whitespace B'cuz this forum not allow to use more whitespace.
---------------------------------------
I sperate by whitespace not work.

awk 'BEGIN {FS=" "} {print $2}' testfile

Result is

this
alias

When i add more whitespace Ex. " " it not work too.
i need "this is hostname"
Can sperate it by more whitespace(not fixed) and ignore one whitespace?
Thank you in advance

awk '{sub(/^[ \t]*[[:alnum:]]+[ \t]*/,x)}1' file

Does that serve your purpose?

Use code tags to surround code and data samples ( your code/data ). That'll preserve the white-spaces.

1 Like

How about using sub function?

awk '/hostname/{sub(/[ \t]+hostname[ \t]+/,x);print}' filename

It works!! Thank you all.
And some technic for preserve the white-spaces.I'm newbie.
And I just try

awk 'BEGIN {FS="  +"} {print $3}' test 

It work too :slight_smile:

You do not need the BEGIN section for FS

awk -F" +" '{print $3}' test