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@email.com:phoneexample

username.email.txt - contains:

user1:email@email.com
user131:email@email.com

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
...
  • What's wrong with awk ... /directory/folder/example/file*.txt > out.txt? – B Layer Sep 10 '18 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 '18 at 9:12
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.