Jam*_*own 12
以下是使用awk执行此操作的一种方法:
$ awk '{for(i=1;i<=NF;i++)if($i=="sample")print $(i+1)}' file
text
Run Code Online (Sandbox Code Playgroud)
和sed:
$ awk '{
for(i=1;i<=NF;i++) # process every word
if($i=="sample") # if word is sample
print $(i+1) # print the next
}' file
Run Code Online (Sandbox Code Playgroud)
和使用PCRE的grep和积极看待背后:
$ sed -n 's/.* sample \([^ ]*\).*/\1/p' file
text
Run Code Online (Sandbox Code Playgroud)