从主机名中提取文本

从主机名中提取文本

本文介绍了从主机名中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OS X,我需要一个bash脚本来查看客户端mac主机名,例如:12345-BA-PreSchool-LT.local

Using OS X, I need a one line bash script to look at a client mac hostname like:12345-BA-PreSchool-LT.local

前5位数字是资产序列号,连字符将业务单位代码与部门名称分隔开,后跟类似"LT"的符号来表示便携式计算机.

Where the first 5 digits are an asset serial number, and the hyphens separate a business unit code from a department name followed by something like 'LT' to denote a laptop.

我想我需要回显主机名,并结合使用sed,awk和也许要切掉的字符以使我离开:
"BA PreSchool"

I guess I need to echo the hostname and use a combination of sed, awk and perhaps cut to strip characters out to leave me with:
"BA PreSchool"

任何帮助,不胜感激.这是我到目前为止的内容:

Any help much appreciated. This is what I have so far:

echo $HOSTNAME | sed 's/...\(...\)//' | sed 's/.local//'

推荐答案

 echo "12345-BA-PreSchool-LT.local" | cut -d'-' -f2,3 | sed -e 's/-/ /g'

(不在OSX上,因此不确定是否定义了剪切)

(Not on OSX, so not sure if cut is defined)

这篇关于从主机名中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:26