Re: Shell question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/28/2016 01:02 AM, Joachim Backes wrote:
On 12/27/2016 11:49 PM, JD wrote:
Reading lines from 2 files in such a way that each iteration
lets me read the next line from each file so that the items
read from each file are in sync as far as line number is concerned.
Is this "doable"?

For a single file, indexing to next line is automatic, visa vis
while read line; do
echo $line
done < some_file.txt

for when more than 1 file is involved, it is not so easy ...

JD,

If using the bash, you could introduce file descriptors for each file you are reading from ( set the fie descriptor by using the exec command) and then read using the -u option for each file.

Indeed!  I was just working on a script that has lines like:
    exec 3< <(gunzip -fc "$Infile_1z" | tr '\0' '\n')
    exec 4< "$Infile_2"
    ...
    while [[ various_conditions ]]; do
        read -r -u 3 Data1 || break
        read -r -u 4 Data2 || { echo "EOF on $Infile_2"; exit 1; }
        ...
    done

The reads stay in sync just fine.

--
Bob Nichols     "NOSPAM" is really part of my email address.
                Do NOT delete it.
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]
  Powered by Linux