问题
I have a text file in a Solaris workstation. Please see a sample of contents of the file below (The number of entries can vary):
CMSBC01 TELNET_APG40
CMSBC01_1 TELNET_APG40
CMSBC03 TELNET_APG40
CMSBC03_1 TELNET_APG40
GMSC1 TELNET_APG40
GMSC2 SSH_APG40
I am only interested about the 1st column entries. I want the output to be :
CMSBC01
CMSBC01_1
CMSBC03
CMSBC03_1
GMSC1
GMSC2
I have tried
awk -F\; '{print $1}' /home/els/axelist.txt
and also:
cat axelist.txt | sed 's/ *//'
But still not able to extract the 1st column. Any help is welcome.
回答1:
This should work:
awk '{print $1}' axelist.txt
The default field separator in awk
is any sequence of whitespace.
With sed it should be:
sed 's/ .*//' axelist.txt
You were missing the .
, so it was just removing the spaces, not everything after the spaces.
来源:https://stackoverflow.com/questions/25010893/truncate-trailing-characters-in-solaris