I have two files in my linux server.
File 1
9190784
9197256
9170546
9184139
9196854
File 2
S NO.,Column1,Column2,Column3
72070,9196854,TGM,AP
72071,9172071,BGM,MP
72072,9184139,AGM,KN
72073,9172073,TGM,AP
I want to write a script or a single line command in bash using awk command, so as whatever the element in File -1 should match the same with column 1 in File -2 and print Column 1, Column2 and Column3. Also if any entry is not found it should print entry from file 1 and print NA in Column 2 and Column 3
Output : it should redirect the output to a new file as below. new_file
9190784,TGM,AP
9197256,NA,NA
9170546,NA,NA
9184139,AGM,KN
9196854,TGM,AP
I hope the query is understandable. Anyone please help me on the same.
cat * | cut -d "|" -f 2 | awk '$1 {print substr($1,1,7)}'| head -5
have to do withfile 1
and the list of strings you show under it? Is that a command you're running onfile 1
to produce those strings as output (in which case just show us file 1) or is it the command thats generatingfile 1
or something else? The columns you say you want to print don't match the output you say you want. Tidy up your question to be clear and consistent so we can help you. – Ed Morton