Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在贝壳中,
s="abc\tdef\tghi" # 3 words separated by \t
如果我想得到第二个单词def怎么办?
def
附言
我知道cut可以完成这项工作,但是还有什么方法可以像变量替换一样吗?
cut
怎么样cut?
[cnicutar@ariel ~]$ echo -e $s | cut -f2 def
或者也许awk:
awk
echo -e $s | awk '{print $2}'
也许你正在寻找这个。
s="abc\tdef\tghi" s=${s#*\t} s=${s%\\t*} echo $s