0

I have a file containing the following string with hundreds of these lines:

Jun 30;donotreply@my.com;user@example.com
Jun 30;donotreply@my.com;user2@example2.com
Jun 30;donotreply@my.com;user3@example.net
Jun 30;donotreply@my.com;user4@example.org

And tried

VARIABLE=example.net
awk -F ";" ~ $3 /$VARIABLE/

is not working

I also tried, awk -v var="$VARIABLE" -F ";" '$3 ~ /var/' : but it is also not giving any results

How can we add variable inside \ \

TPS
  • 493
  • 1
  • 5
  • 28
  • You do not need `/` in the last example, see https://ideone.com/HKePeH. Note the `.` must be escaped to match a literal `.` char. – Wiktor Stribiżew Jul 01 '20 at 10:46
  • 2
    Use `awk -v var="$VARIABLE" -F ";" '$3 ~ var'` or better use `index` function instead of `~` – anubhava Jul 01 '20 at 10:46
  • @anubhava, I am trying to get a full line which contents example.net at 3rd position. How can I achieve this with index? @Wiktor link you provided is not valid and I am not trying to escape `.` char. – TPS Jul 01 '20 at 12:11
  • Use: `awk -v var="$VARIABLE" -F ";" 'index($3, var)' file` should do the job – anubhava Jul 01 '20 at 14:06

0 Answers0