Awk Grep模式并选择匹配模式后的部分
Grep pattern并选择匹配模式41572:90000:90002之后的行部分: 输入Awk Grep模式并选择匹配模式后的部分,awk,Awk,Grep pattern并选择匹配模式41572:90000:90002之后的行部分: 输入 hyt : generation str : 122344 stks : 9000233 dhy : 9000aaaa sjyt : hist : hhh9000kkk Count ch : 41572:47149-47999/2(14485-14910) 41584:47149-47999/2(14911-15449) 90000:47919-47999/2(15447-15477) 90002:47
hyt : generation
str : 122344
stks : 9000233
dhy : 9000aaaa
sjyt : hist : hhh9000kkk
Count ch : 41572:47149-47999/2(14485-14910) 41584:47149-47999/2(14911-15449) 90000:47919-47999/2(15447-15477) 90002:47919-47999/2(15478-15418)
drx : 12345
hyt : generation
str : 122344
stks : 9000233
dhy : 9000aaaa
sjyt : hist : hhh9000kkk
41572:47149-47999/2(14485-14910) 90000:47919-47999/2(15447-15477) 90002:47919-47999/2(15478-15418)
drx : 12345
这里是使用的代码
awk '
{
flag=""
for(i=1;i<=NF;i++){
if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){
flag=1
printf("%s%s",$i,i==NF?ORS:OFS)
}
}
}
!flag
' Input_file
我需要以下所需输出
hyt : generation
str : 122344
stks : 9000233
dhy : 9000aaaa
sjyt : hist : hhh9000kkk
Count ch : 41572:47149-47999/2(14485-14910) 90000:47919-47999/2(15447-15477) 90002:47919-47999/2(15478-15418)
drx : 12345
提前感谢编辑:根据OP的新问题添加解决方案
awk '{flag="";for(i=1;i<=NF;i++){if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){flag=1;printf("%s%s",$i,i==NF?ORS:OFS)}}} !flag'
awk'{flag=”“;for(i=1;i1{for(i=1;i1{
对于(i=1;i1{###检查NF是否大于1。
对于(i=1;我不清楚,你能不能在你的问题中更清楚一点,预期输出背后的逻辑是什么。RavinderSingh13,是的,正是我需要得到的输出。。不容易解释逻辑。@OXXO,编写解释将在几分钟内添加它。@OXO,请现在检查,并让我知道是否有任何疑问。RavinderSingh13,tks很多代码工作正常p非常适合第一个输入示例。您是否有机会添加或修改代码以使用Example2输入并获得所需的输出,@OXXO,请立即检查我的编辑。
awk '
{
flag=""
for(i=1;i<=NF;i++){
if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){
flag=1
printf("%s%s",$i,i==NF?ORS:OFS)
}
}
}
!flag
' Input_file
awk 'NF>1{for(i=1;i<=NF;i++){if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){printf("%s%s",$i,i==NF?ORS:OFS)}};next} 1' Input_file
awk '
NF>1{
for(i=1;i<=NF;i++){
if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){
printf("%s%s",$i,i==NF?ORS:OFS)
}
}
next
}
1
' Input_file
awk '
NF>1{ ##Checking if NF is greater than 1.
for(i=1;i<=NF;i++){ ##Using for loop to go through from value 1 to till value of NF.
if($i ~ /41572/ || $i ~ /90000/ || $i ~ /90002/){ ##Checking if value of fields is either 41572 OR 90000 OR 90002 then do following.
printf("%s%s",$i,i==NF?ORS:OFS) ##Print the field value in case above condition is TRUE with NEW line if i==NF or space if not.
}
}
next ##Next will skip all further statements from here.
}
1 ##1 will print all edited/non-edited lines here.
' Input_file ##Mentioning Input_file name here.