0

I have multiple text files in a folder that I want to process through gawk, rather than process them each individually is it possible I can process them all at once without merging them into 1 .txt file

Example of script -

"C:\cygwin64\bin\gawk.exe" -F: 'FNR==NR{a[$1]=$2;next} $2 in a{print $1 FS a[$2]}' email.phone.txt username.email.txt > username.phone.txt

Example of usage -

email.phone.txt - contains:

[email protected]:phoneexample

username.email.txt - contains:

user1:[email protected]
user131:[email protected]

EXPECTED OUTPUT:

user1:phoneexample
user131:phoneexample

but rather than process one of

email.phone.txt

files could i process a directory full of them?

Example -

C:/directory/folder/example

containing:

file1.txt
file2.txt
file3.txt
...
2
  • What's wrong with awk ... /directory/folder/example/file*.txt > out.txt?
    – B Layer
    Sep 10, 2018 at 4:45
  • It seems you want to merge 2 file types, but it is not clear if the full operation is two sets or one set versus one type.
    – matzeri
    Sep 10, 2018 at 9:12

1 Answer 1

0

So, you have one file mapping user to email, and several files mapping email to phone. Yes, awk can do this: just process the user:phone file first

gawk -F: -v OFS=: '
    NR == FNR  {user[$2] = $1; next} 
    $1 in user {print user[$1], $2}
' user.email.txt email.* > user.phone.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .