0

I am working on 2 files:

File1:

Data Source=xyz,61375;User ID=user;Password=[MASKED];Connect Timeout=30;Encrypt=True;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Value1
Value2

File2:

APPCONFIG.SqlServer__ConnectionString
TES1.PROP__KEY1
TES1.PROP__KEY2

I want to use Awk command to save each line from File1 into a new file named using each line of File2

Expected output:3 new files with following names:

/# ls
APPCONFIG.SqlServer__ConnectionString 
TES1.PROP__KEY1
TES1.PROP__KEY2

/# cat APPCONFIG.SqlServer__ConnectionString 
Data Source=xyz,61375;User ID=user;Password=[MASKED];Connect Timeout=30;Encrypt=True;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

/# cat TES1.PROP__KEY1
Value1

/# cat TES1.PROP__KEY2
Value2
1

If you merge the files with paste it becomes quite straightforward, e.g.:

paste file2 file1 | awk -F'\t' '{ print $2 > $1; close($1) }'
1
  • Thanks a lot! this worked perfectly
    – Pooja Arya
    Nov 13 '19 at 8:09

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.