Skip to content
Advertisement

How to read a file line by line

I try to read a file line by line.

File to read:

JavaScript

Script:

JavaScript

When I execute the script, this window will be opened: (Notice how some values are repeated, and the contents don’t correctly alternate between names and versions): Xdialog window

I’d like to create an array with all package names and versions.

Advertisement

Answer

You don’t need a counter for this at all, and invoking head twice for every single line is insanely inefficient.

JavaScript

See BashFAQ #001: How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement