03-30-2006
Getting a line of a file by number
I was wondering if their is a command that will output a line of a file by number. I mean i know how number a file but what i'm looking for is to pull a line out of a file by refering to its line number. Is their anyway of doing this. Thanks in advance
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I want to get a specific line form file by line number.
For example
I have file named bla
File looks like this
cat bla
Madrid
Paris
Berlin
Vladivostok
I want to put line 3 (Berlin) into variable X.
How to do that? (3 Replies)
Discussion started by: corny
3 Replies
2. Shell Programming and Scripting
Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one.
I want to basically append to each line in a file a delimiter character and the line's line number e.g
Change the file from :-
aaaaaa
bbbbbb
cccccc
to:-
aaaaaa;1
bbbbbb;2
cccccc;3
I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies
3. Shell Programming and Scripting
I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script
# Get randome line number from the file
#selectedline = `awk... (1 Reply)
Discussion started by: zambo
1 Replies
4. Shell Programming and Scripting
Hi Everybody,
I am trying to write a script that will get some perticuler data from a file and redirect to a file.
My Question is,
I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line.
I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies
5. UNIX for Dummies Questions & Answers
Hello Everyone.
I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below:
if ; then
if ; then
tail +$1 $3 | head -n $2
else
... (5 Replies)
Discussion started by: grc
5 Replies
6. Shell Programming and Scripting
Hi guys,
is there are way to substitute the content of certain line in the file by another entry if line number is available?
For example, I have a variable A="HCMLPBBG" and a file MYFILE.
I need to substitute entry on line 18168 of MYFILE with the value of the variable "A".
Is there a way to... (1 Reply)
Discussion started by: aoussenko
1 Replies
7. Shell Programming and Scripting
Hi All,
Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example :
abc.txt
7000,john,2,1,0,1,6
7001,elen,2,2,0,1,7
7002,sami,2,3,0,1,6
7003,mike,1,4,0,2,1
8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies
8. Shell Programming and Scripting
Hi,
I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@,
for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies
9. Shell Programming and Scripting
Sed command to replace a line in a file using line number from the output of a pipe.
Is it possible to replace a whole line piped from someother command into a file at paritcular line...
here is some basic execution flow..
the line number is 412
lineNo=412
Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies
10. Shell Programming and Scripting
I have few lines in a text file. I am trying to get the line number of uncommented line from the text file using unix shell script.
For example : I want the line number of Orange from the below text file. Here expected answer is 4 since the line 2 is commented.
Apple
#Orange
grapes
Orange (4 Replies)
Discussion started by: Brennon
4 Replies
line(1) User Commands line(1)
NAME
line - read one line
SYNOPSIS
line
DESCRIPTION
The line utility copies one line (up to and including a new-line) from the standard input and writes it on the standard output. It returns
an exit status of 1 on EOF and always prints at least a new-line. It is often used within shell files to read from the user's terminal.
EXIT STATUS
Exit status is:
0 Successful completion
>0 End-of-file on input.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
sh(1), read(2), attributes(5)
SunOS 5.10 1 Feb 1995 line(1)