Display a particular line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display a particular line from a file
# 1  
Old 07-31-2006
Display a particular line from a file

Hi,

What is the command i can use iof i want to display a particular line from a file, i have the line number with me.
# 2  
Old 07-31-2006
head -n filename | tail -1
n = linenumber
# 3  
Old 07-31-2006
Code:
sed -n "${line_number}p"  $filename

# 4  
Old 07-31-2006
Hi Friends,

Thank you so much, now i have 2 options to achieve the functionality.
# 5  
Old 07-31-2006
Hi Klashxx,

The command is serving the purpose but can you please let me know the meaning of the options supplied :

sed -n "linenumber p" filename

i know p option is to print ... but how does -n work.

This is only for my knowledge.

Thanks again !
# 6  
Old 07-31-2006
The -n flag suppress automatic output of input lines.

Cheers.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to display certain line of file only using head or tail in 1 command?

First month learning about the Linux terminal and it has been a challenge yet fun so far. We're learning by using a gameshell. I'm trying to display a certain line ( only allowed 1 command ) from a file only using the head or tail. I'm pretty about this answer: head -23 history.txt | tail -1... (1 Reply)
Discussion started by: forzatekk
1 Replies

2. Shell Programming and Scripting

Search first file line after Error and display

I have a log file which contains information like below (more than 200 ERROR sets). Here I want to find first .c file and function after "ERROR: AddressSanitizer" line. If you see here after "ERROR:" line first file - asfrecohandling.c function - ASFPotRecoHandling_Create_RecPaxSrvcComp ... (6 Replies)
Discussion started by: pushpabuzz
6 Replies

3. Shell Programming and Scripting

Display the file name on each line using awk

How do I display the filename that has been awk to each of the line in Unix, i need to so far I have tried {print FILENAME;nextfile} but to no avail. `awk -F, '/1.2 Install TCP Wrappers/ {P=0} /1.1 Apply latest OS patches/ {P=1} P' solarisappsummary.txt solarisdbsummary.txt` For... (6 Replies)
Discussion started by: alvinoo
6 Replies

4. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

5. Shell Programming and Scripting

How to display the line number of file while searching for a pattern

awk 'BEGIN{IGNORECASE=1} /error|warning|exception/ { ++x } END { print x }' filename The above command returning the number of times the pattern present in the file. But I want the the line number as well. please help me out (6 Replies)
Discussion started by: arukuku
6 Replies

6. Shell Programming and Scripting

Display 3rd line of a file using cut only

Hello, i want to use new line character in cut command i want to display 3rd line of a file using cut only( not by sed or head -tail command) can anyone suggest me ? Regards (12 Replies)
Discussion started by: Deepak Dutt
12 Replies

7. Shell Programming and Scripting

Display mutiple line in single line

Hi All, I had a file called Input.txt, i need to group up in a single line as 1=ttt and the no of lines may vary bewteen the 1=ttt cat Input.txt 1=ttt,2=xxxxxx, 3=4545 44545, 4=66667 7777, 5=77723 1=ttt, 2=xxxxxx, 3=34436 66 3545, 4=66666, 5=ffffff, 6=uuuuuuu 1=ttt, 2=xxxxxx,... (4 Replies)
Discussion started by: manosubsulo
4 Replies

8. Shell Programming and Scripting

Unable to display correctly the contents of a file without a line feed

I am using AIX and ksh. I need to display the contents of a file that has a pid (process id). Because the file is open, it doesn't have the line feed or new line, so for some reason if I do this: `cat $pid` , where $pid is the name of the fully qualified file, it displays test3.sh: 426110:... (1 Reply)
Discussion started by: Gato
1 Replies

9. UNIX for Dummies Questions & Answers

Want display a line with space in file by unix script

HI , I am having a file as -----------------a.out------------------- Hi I am unix developer using hp unix this is a test --------------------------------------- i need to read each line by a unix script of the file and to print in console with the space in the line as ... (9 Replies)
Discussion started by: arunkumar_mca
9 Replies
Login or Register to Ask a Question