How do you read / process 2 files in sync with each other in sync?
I have 2 text files in which they have the same line numbers / items in one file
ABC is another file
1 2 3 How can I loop through sync in these files so that a 1 , b-> 2, c-> 3? I thought that I can read files as an array and then process them with an index but it seems that my syntax / argument is wrong.
By doing this, f1 = $ (cat File1) creates f1 = abc . I thought that f1 = ($ (cat file1)) will make it in an array, but it creates f1 = a and thus there is no array to process for me is not. If someone was wondering what my wrong code is:
hostnames = ($ (cat $ host_file)) # trying to read as an array For obviously the wrong roles = ($ (cat $ role_file)) I echo $ {hostname {$ i]} in {0..3} # again through file / array # element in each element , But instead of N, only one object is objects $ {rolls [$ i]}
Use paste Not () to combine the files, then the process of a line of joint file at a time: paste file1 file2 | While reading -r first second do the first resonant $ second
No comments:
Post a Comment