i is an integer (lets say 4). I have three text files (a,b,c) contain single lines with strings, total number of lines of files equal to i (4). For example "a" file contains;
trm320
abc000
dfg1002
der5205
I need to create the output (on the screen or in the text file) with loop like;
a(1) b(1) c(1) (first line of a,b,c files)
a(4) b(4) c(4) (last line of a,b,c files)
What kind of loop do I need to create?
paste
does exactly what you want.In your case
will do the trick. If you need the output in a file, redirect
>output
the output.To access the
n-th
line of a file, usesed
. For convenience wrap it up in a Bash function (pl
is supposed to mean Print Line)Calling for example
pl 5 a
will print the fifth line of filea
. To store it in a variableor combine both tasks
to print the fifth line of the concatenated file.
To get a file into an array, use
mapfile
, from this answer: