How would you print just the 25th line in a file (smallest possible script please)?

Showing Answers 1 - 75 of 158 Answers

Rishi

  • Jun 6th, 2005
 

sed -n '25p' filename.txt

Vijay Roy

  • Jan 25th, 2006
 

echo "Enter User Name "read nameecho "Enter passwd "stty -echoread passstty echo sqlplus -s $name@oracle/$pass<

  Was this answer useful?  Yes

Vijay Roy

  • Jan 25th, 2006
 

echo "Enter User Name "read nameecho "Enter passwd "stty -echoread passstty echo sqlplus -s $name@oracle/$pass<

  Was this answer useful?  Yes

ruchi sharma

  • Oct 13th, 2006
 

 head -25 filename|tail -1

punitha

  • Mar 7th, 2007
 

cat -n filename | grep '25'

bhanu_tadiboina

  • May 17th, 2007
 

head -25 file| tail -1 goes wrong because if some one deletes some lines even then it gives last line as 25th line.
so the right option is

tail +25 file| head -1

  Was this answer useful?  Yes

Sri

  • Jul 11th, 2007
 

I think both the command results with same answers

  Was this answer useful?  Yes

Abhijeet

  • Jul 13th, 2007
 

tail -n +25 | head -1 OR
head -n 25 | tail -1

s4srinivas

  • Oct 15th, 2007
 

cat -n <filename>|grep '25'

goes wrong if the file has 25 in anyof the lines

srinath prakashnaidu

  • Oct 26th, 2007
 

head -25 |tail -1

  Was this answer useful?  Yes

Following command will give the required output.

head -25 <filename> | tail -1


Head will get the first 25 lines, whereas tail will get the last line of the 25 lines (i.e. 25the line).

  Was this answer useful?  Yes

my_thoughts

  • Feb 14th, 2010
 

Both of them would mean the same.
You ruled out first option saying that someone might delete the starting lines.
The same case would be with 2nd option if someone deletes the ending lines.

  Was this answer useful?  Yes

Furkan

  • Mar 30th, 2012
 

cat ( x in file)
do
if [ $line -eq 25 ]
then
echo $line
fi
done

  Was this answer useful?  Yes

Giridhar

  • Mar 31st, 2012
 

head -25 filename | tail -n +25

  Was this answer useful?  Yes

Mike

  • Apr 8th, 2012
 

head -25 filename | tail -1

  Was this answer useful?  Yes

Mo

  • Apr 20th, 2012
 

sed -n 25p filename or cat -n | grep "^5"

  Was this answer useful?  Yes

Govind Kailas

  • May 10th, 2012
 

A simple perl one liner to print only the 25th line

Code
  1. perl -ne $. == 25 && print && exit

  Was this answer useful?  Yes

Patricia

  • May 25th, 2012
 

in bash:

cat $filename | awk {print $25 }

  Was this answer useful?  Yes

Jessmon

  • Jun 1st, 2012
 

Code
  1. head -n25 $filename |tail -n1

  Was this answer useful?  Yes

SGN

  • Jun 12th, 2012
 

send -n 25 p

  Was this answer useful?  Yes

Gaurav

  • Oct 2nd, 2012
 

awk NR==25 {print $0} file

  Was this answer useful?  Yes

AP

  • Nov 11th, 2012
 

file + 25 | head -1

  Was this answer useful?  Yes

Sudha

  • Dec 7th, 2012
 

head -25 file | tail -1
sed -n {25p} file
sed {26,$d} file | sed {1,24d}

  Was this answer useful?  Yes

Sudhin

  • Jan 11th, 2013
 

head -25 | nl | tail -1

  Was this answer useful?  Yes

Abhishek

  • Feb 21st, 2013
 

awk NR==25

  Was this answer useful?  Yes

Rajendra Prasad

  • Jun 5th, 2013
 

sed -n 25p filename(a.txt)

  Was this answer useful?  Yes

Rajendra Prasad

  • Jun 7th, 2013
 

head -25 filename|tail -1

  Was this answer useful?  Yes

Piyush K

  • Aug 25th, 2014
 

cat -n Filename | grep ^25

  Was this answer useful?  Yes

Inesh

  • Aug 25th, 2014
 

sed -n 25p filename

  Was this answer useful?  Yes

Dibya

  • Aug 26th, 2014
 

• sed -n 10p
• cat -n | sed -n 10p
• sed -n 10p
• head -10 | tail -1
• sed -n 1,10p | tail -1
• cat | head -10 | tail -1
• head -10 | tail +10

  Was this answer useful?  Yes

Manas

  • Sep 16th, 2014
 

head -25 |tail -1

  Was this answer useful?  Yes

Rakesh

  • Sep 18th, 2014
 

sed -n 25p file_name

  Was this answer useful?  Yes

Anirban

  • Feb 2nd, 2015
 

Code
  1. show kth line:

  2. cat file|tail -n +k |head -1

  Was this answer useful?  Yes

Don Alom

  • Mar 18th, 2015
 

awk { if (NR==25) print $0} filename

  Was this answer useful?  Yes

vikas

  • Mar 20th, 2015
 

sed 25!d

  Was this answer useful?  Yes

Ashka Shah

  • Apr 1st, 2015
 

head -25 | tail -1

  Was this answer useful?  Yes

Mohd Haroon

  • Jul 7th, 2015
 

awk NR==25 filename

  Was this answer useful?  Yes

Ajay Barik

  • Jul 9th, 2015
 

sed -n 25p filename

  Was this answer useful?  Yes

santosh

  • Aug 3rd, 2015
 

awk -F "" NR == 25 {print $0}

  Was this answer useful?  Yes

aniket

  • Aug 12th, 2015
 

head -25 file.txt | tail -1

  Was this answer useful?  Yes

kian

  • Aug 23rd, 2015
 

sed -n 25 p file.txt

  Was this answer useful?  Yes

gaurav Sharma

  • May 16th, 2017
 

awk NR==25 aa.sh

  Was this answer useful?  Yes

Yogesh

  • Aug 31st, 2017
 

head -25 filename | tail -1

  Was this answer useful?  Yes

Ashok

  • May 27th, 2018
 

sed -n 25p filename.txt

  Was this answer useful?  Yes

Shwetha N A

  • Jun 25th, 2021
 

tail +25 filename | head -1

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions