AWK 模式中使用变量

[root@test test]# cat file
spam ksjfkd   spam
ksdjfks spam sldkjfkd
skdfj la sdfkj sfsal fals f
kdsfj   spam   kdjfksjf
skdf lsf lsf slf s f
ksdjfk skdjfks spam
kkkj sdkfjs sdkfjls lsdjf s
ksdjff ksjfsl   lksjdf kj fas 
spam lskdjfl asslkdf as fs spam 
slkf spam ls dflak fsdf lsdf 
[root@test test]# awk -v Sname='spam' '$1 ~ Sname {print } ' file 
spam ksjfkd   spam
spam lskdjfl asslkdf as fs spam 

你可能感兴趣的:(模式,awk,使用变量)