Unix Awk Script
Awk Script
1. Print Even number of words in each line from file
Ans.
awk '{for(i=1;i<=NF;i++)
if(i%2==0)
printf("%s ",$i)
else
continue
printf("\n")
}' file1
O/P:-=
is command
file created awk
{file1:-
this is awk command example
this file is created for awk
}
2. Display words having length greater than 10 and consists of digit.
Ans.
awk '{for(i=1;i<=NF;i++)
if(length($i)>10)
if(int($i))
printf("%s ",$i)
else
continue
printf("\n")
}' file2
O/p:
12345678912
{file2:
this is number file 123445
123456789 hcd kkd 72 7832
12345678912 1234156789
124 edne 124de edj 12dw ds5
asjkdeyfendj fdej kjd faiuendhgej
dk fdkfj87fdnj77n dfjn jhfd hude7634bfdef
}
Awk Script
1. Print Even number of words in each line from file
Ans.
awk '{for(i=1;i<=NF;i++)
if(i%2==0)
printf("%s ",$i)
else
continue
printf("\n")
}' file1
O/P:-=
is command
file created awk
{file1:-
this is awk command example
this file is created for awk
}
2. Display words having length greater than 10 and consists of digit.
Ans.
awk '{for(i=1;i<=NF;i++)
if(length($i)>10)
if(int($i))
printf("%s ",$i)
else
continue
printf("\n")
}' file2
O/p:
12345678912
{file2:
this is number file 123445
123456789 hcd kkd 72 7832
12345678912 1234156789
124 edne 124de edj 12dw ds5
asjkdeyfendj fdej kjd faiuendhgej
dk fdkfj87fdnj77n dfjn jhfd hude7634bfdef
}
Comments
Post a Comment