Dear Team,
I need support to use awk program to grep data based on matching pattern first 5 digits "96656" .
Data I have as below
466565996656,820012906026651 NA NOTMATCHED
4661740045165,820011902196656 NA NOTMATCHED
4661740085225,820011900196656 NA NOTMATCHED
4665640160118,820011901966563 NA NOTMATCHED
4661740160267,820011901966564 NA NOTMATCHED
4665640160500,820011901966566 NA NOTMATCHED
4661740161648,820011901966568 NA NOTMATCHED
4665640171771,820011902096656 NA NOTMATCHED
Need awk program which filter data as below with first column having first 5 digits matching as "46656"
466565996656,820012906026651 NA NOTMATCHED
4665640160118,820011901966563 NA NOTMATCHED
4665640160500,820011901966566 NA NOTMATCHED
4665640171771,820011902096656 NA NOTMATCHED
I am trying below code
awk -F'=|,|' '$1 == "46656" {print $0}'STG3TOUDCMATCH >> 56_Ser
but this code filtering data with 96656 at any place in 1st column. But I need to filter based on first 5 digit of 1 column that match "96656".
Thanks in advance.
Hi, try:
awk -F, '$1~46656' STG3TOUDCMATCH >> 56_Ser
Thanks but this is not I am looking for. This prints data based on 96656 at any place.
466122896656,820012944069245 NA NOTMATCHED
466135996656,820012906026651 NA NOTMATCHED
4661740045165,820011902196656 NA NOTMATCHED
4661740085225,820011900196656 NA NOTMATCHED
4661740096656,820011900192131 NA NOTMATCHED
4661740160118,820011901966563 NA NOTMATCHED
4661740160267,820011901966564 NA NOTMATCHED
4661740160500,820011901966566 NA NOTMATCHED
4661740161648,820011901966568 NA NOTMATCHED
4661740171771,820011902096656 NA NOTMATCHED
I need to filter data based on first column starting with "96656".
like below
466565996656,820012906026651 NA NOTMATCHED
4665640160118,820011901966563 NA NOTMATCHED
4665640160500,820011901966566 NA NOTMATCHED
4665640171771,820011902096656 NA NOTMATCHED
Assuming that the 1st field of your data starts in the 1st character of each line, try:
awk '/^46656/' STG3TOUDCMATCH > 56_Ser
Note that there must be a space between the single quote at the end of the awk
script and the name of the file awk
is supposed to process.
If you only want a line filter then grep is perfect
grep '^46656' STG3TOUDCMATCH
If you later want to add more field-based filters or output formatting then use awk with its automatic field splitting
awk -F, '$1~/^46656/' STG3TOUDCMATCH
For example, you can add a condition "and field#2 must end with 56"
awk -F, '$1~/^46656/ && $2~/56$/' STG3TOUDCMATCH