I am trying to use awk - but am able to print only the lines which match the pattern. The lines which donot match the pattern are getting removed. Please help.
Following may help you in same, let me know if you have any queries.
awk 'NR==FNR ####### This condition will be TRUE when first file named file is being read, because FNR attribute will be RESET when new file will be read and NR will be keep on increasing it's count till last file read successfully.
{T[$1]=FS $1; next} ####### Creating an array named T whose index is $1 and value is FS(Field separator which is , here mentioned later in code), after doing this next means leave all coming statements, NOT to execute.
{print $0 T[$1]}' ####### This will be executed when 2nd file is being read because when NR==FNR will NOT be TRUE then control will come here and execute it, to print the complete line by $0 and print array T's value whose index is $1.
FS="," file1 file2 ####### mentioning Field separator here which is comma and mentioning Input_file which are file1 and file2.
EDIT: For your question setting FS before the value of array named T because while printing them(which will happen while file2 is being read) we are not giving the field separator there and as per your requirement we need it so that is why we are doing this, also one benefit of this approach is if $1 of file2 is not present in file1 so it will NOT simply print field separator, which is not your requirement.