【发布时间】:2012-07-19 23:32:38
【问题描述】:
我有一个制表符分隔的文本文件,结构如下:
word0 word1 word2 word3 word4 word5 word6
从我想要的 linux commond 行:
- 只获取word6
- 如何只获取 word6 中的字符 ord6?
【问题讨论】:
我有一个制表符分隔的文本文件,结构如下:
word0 word1 word2 word3 word4 word5 word6
从我想要的 linux commond 行:
【问题讨论】:
AWK 可以做到这一点:
$ echo "word0 word1 word2 word3 word4 word5 word6" | awk '{ print $(NF) }'
word6
【讨论】:
sed -E 's/.(...)./\1/',例如,您会得到 ord。
您可以使用简单的cut 命令:$cut -d'Press CTRL+v then TAB key to insert tab as delim here' -f6 textfile|cut -c2-
ord6
$
查看 cut 命令的手册页了解更多信息。
当然,还有很多其他方法可以做同样的工作。
【讨论】:
试试这个
awk -F "\t" '{print $NF}' Input.txt
根据需要更改分隔符。
【讨论】:
string=$(echo "word0 word1 word2 word3 word4 word5 word6" | awk '{ print $(NF) }')
echo ${string:3:4} # echo substring starting at postion3, 4 characters long i.e. ord6
或
echo ${string[@]#w} # removes the shortest possible match for the regex
# (i.e. w) at the start of the string
## 最长匹配,% & %% 删除字符串的后面
【讨论】: