I have a datafile in the following format
1|col2|col3|105,230,3,44,59,62|col5
2|col2|col3|43,44|col5
3|col2|col3|1,2,3,4,5,6,7,8|col5
4|col2|col3|1,2,37|col5
So, desirable records from above given data are
1|col2|col3|105,230,3,44,59,62|col5
3|col2|col3|1,2,3,4,5,6,7,8|col5
I'm currently using the following command but I'm looking for a more efficient/organized one
awk -F"|" '$4 ~ /,3,/ || $4 ~ /^3,/ || $4 ~ /,3$/'
Short GNU awk
solution:
awk -F'|' '$4 ~ /\<3\>/' file
\<
and \>
- stand for the start and end of the word respectively The output:
1|col2|col3|105,230,3,44,59,62|col5
3|col2|col3|1,2,3,4,5,6,7,8|col5
Or a more unified/portable one:
awk -F'|' '$4 ~ /(^|,)3(,|$)/' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With