Truncate trailing characters in Solaris

白昼怎懂夜的黑 提交于 2019-12-11 08:45:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!