3

I am trying to search a pattern stored in awk array "a" read from file1 and then search in 4rth column of file2 , the following command works perfectly

awk -F" " 'NR==FNR{a[NR]=$1;next}{for (i in a){ if($4 ~ a[i])print $0}}'  file1 file2 

but If I change the command at if to search at the start of 4rth column of file2 as shown below , it does not work , any suggestions please ?

awk -F" " 'NR==FNR{a[NR]=$1;next}{for (i in a){ if($4 ~ "^a[i]" )print $0}}'  file1 file2 

can the second command be modified to search the array element at the start of 4rth column in file2 ?

1 Answer 1

7

Change "^a[i]" to "^"a[i]......

Sign up to request clarification or add additional context in comments.

1 Comment

My goodness!! , Thanks ED, I realised that I can also combine regular expressions just like "^"a[i]".*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.