M
M
moskovschuk2020-01-01 22:12:15
linux
moskovschuk, 2020-01-01 22:12:15

Extracting a specific line (by number) bash?

Hello! I am writing a script to set up a network and I need to extract the names of the network interfaces and add them to a variable accordingly. First of all, I greped out their names, and now I have the names of network interfaces for each interface on a new line. I need to add each interface to a variable, I tried awk, but I can't select the second, third line. How to implement so that each new line is extracted?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2020-01-02
@xotkot

the task is not entirely clear, but perhaps it will be easier for you to drive the strings into an array

$ cat lines.txt
lan1
lan2
lan3

$ lines=(`cat lines.txt`)

$ echo ${lines[0]}
lan1
$ echo ${lines[1]}
lan2
$ echo ${lines[2]}
lan3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question