Hi All,
I am new to scripting.
I have a requirement where I need to search for token present in array in a file. If the token is found I need to take the first column of that line from the file and append it to token and direct it to a new file.
e.g. token file
token.txt contains
abc
der
xyz
flat.txt contains
123 abc
234 der sgd
345 wse xyz
000 qwe qaws zksd
expected output
abc 123
der 234
xyz 345
I tried using following code but its not working.
filearray=( `cat token.txt | tr '\n' ' '`)
for ((i=0;i<${#filearray
[*]};i++))
{
awk '{for (f=NF; f>=0 ; f--) if ($f ~/${filearray}/) {print $filearray, $1,; next}}' flat.txt} >> newfile.txt
exit
.
Appreciate your help.