截断Solaris中的尾随字符 [英] Truncate trailing characters in Solaris
本文介绍了截断Solaris中的尾随字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CMSBC01 TELNET_APG40
CMSBC01_1 TELNET_APG40
CMSBC03 TELNET_APG40
CMSBC03_1 TELNET_APG40
GMSC1 TELNET_APG40
GMSC2 SSH_APG40
我只对第一列条目感兴趣。我想要的输出是:
CMSBC01
CMSBC01_1
CMSBC03
CMSBC03_1
GMSC1
GMSC2
我试过了
awk -F\; '{print $ 1}'/home/els/axelist.txt
还有:
cat axelist.txt | sed's / * //'
但仍然无法提取第一列。
欢迎任何帮助。
解决方案
awk'{print $ 1}'axelist.txt
使用sed,它应该是:
sed's /。* //'axelist.txt
您错过了。
,所以它只是删除空格,而不是空格之后的所有内容。
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.
解决方案
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.
这篇关于截断Solaris中的尾随字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文