Print 2nd line in text file

head -2 filename | tail -1 | cut -d ':' -f 1   

I'd suggest awk for this kind of task:

awk -F: 'NR==2 {print $1}' filename

Alternatively with sed:

sed -n '2s/:.*//p' filename

If the file is large, you may want to change those to

awk -F: 'NR==2 {print $1; exit}' filename

and

sed -n '2{s/:.*//p;q;}' filename

respectively, to avoid unnecessarily processing later lines.


grep -m 2 -o '.*' filename | cut -d ':' -f 1 | tail -n 1

Results:

10.10.10.170

tail -n 1 prints only the last line of the results of grep -m 2 -o '.*' filename | cut -d ':' -f 1

The original text file is named filename.