我有一大堆看起來像這樣的英語單詞。
1. do accomplish, prepare, resolve, work out
2. say suggest, disclose, answer
3. go continue, move, lead
4. get bring, attain, catch, become
5. make create, cause, prepare, invest
6. know understand, appreciate, experience, identify
7. think contemplate, remember, judge, consider
8. take accept, steal, buy, endure
9. see detect, comprehend, scan
10. come happen, appear, extend, occur
11. want choose, prefer, require, wish
12. look glance, notice, peer, read
13. use accept, apply, handle, work
14. find detect, discover, notice, uncover
15. give grant, award, issue
16. tell confess, explain, inform, reveal
我希望能夠提取第二列,
do
say
go
get
make
know
think
take
see
comer
want
look
use
find
give
tell
任何人都知道如何在 shell bash 中執行此操作。
謝謝。
uj5u.com熱心網友回復:
使用 bash
$ cat tst.sh
#!/usr/bin/env bash
while read line; do
line=${line//[0-9.]}
line=${line/,*}
echo ${line% *}
done < /path/to/input_file
$ ./tst.sh
do
say
go
get
make
know
think
take
see
come
want
look
use
find
give
tell
使用 sed
$ sed 's/[^a-z]*\([^ ]*\).*/\1/' input_file
do
say
go
get
make
know
think
take
see
come
want
look
use
find
give
tell
uj5u.com熱心網友回復:
有很多方法可以做到這一點:
awk '{print $2}' input-file
cut -d ' ' -f 5 input-file # assuming 4 spaces between the first columns
< input-file tr -s ' ' | cut -d ' ' -f 2
< input-file tr -s ' ' \\t | cut -f 2
perl -lane 'print $F[1]' input-file
sed 's/[^ ]* *\([^ ]*\).*/\1/' input-file
while read a b c; do printf '%s\n' "$b"; done < input-file
uj5u.com熱心網友回復:
awk 怎么樣:
cat file.txt | awk '{print $2}'
這行得通嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/377410.html
上一篇:file-i命令不識別由ls命令傳遞給函式的某些檔案
下一篇:如何卸載標簽作業室?
