I have 'file1' with (say) 100 lines. I want to use sed or awk to print lines 23, 71 and 84 (for example) into the file 'file2'. These 3 line numbers are in a separate file, a βlistβ, each number of which is on a separate line.
When I use any of these commands, only line 84 is printed:
for i in $(cat list); do sed -n "${i}p" file1 > file2; done for i in $(cat list); do awk 'NR==x {print}' x=$i file1 > file2; done
Can a for loop be used this way to feed line addresses to sed or awk?
source share