Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me.
I have a file say:
abc
def
ccc
ddd
ffff
The output should be:
Instance1=abc
Instance2=def
Instance3=ccc
Instance4=ddd
Instance5=ffff
... (2 Replies)
Greetings,
I have a file: hostnames.txt which has -
# cat hostnames.txt
machine1
machine2
I need the output to be saved to a variable as:
HOSTNAMELIST=machine1,machine2
Please advise.
Thanks,
Chiru (3 Replies)
Hi
I want to extract certain text between two line numbers like
23234234324 and
54446655567567
How do I do this with a simple sed or awk command?
Thank you.
---------- Post updated at 06:16 PM ---------- Previous update was at 05:55 PM ----------
found it:
sed -n '#1,#2p'... (1 Reply)
Dear all,
I am trying to extract a number from a line in one file (task 1), duplicate another file (task 2) and replace all instances of the strings 300, in duplicated with the extracted number (task 3). Here is what I have tried so far:
for ((k=1;k<4;k++)); do
temp=`sed -n "${k}p"... (2 Replies)
I Have file1 with below lines :
#HostNameSelection=0 :NotUsed
#HostNameSelection=1 :Automatic
#HostNameSelection=3 :NotForced
I have file2 which has similar lines but with different values
I want to copy the changes from file1 to file2 ,line by line only if line begins with '#'.
for... (7 Replies)
I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like:
1 200.3 -0.3
2 201.7 -0.32
...
87 200.2 -0.314
I have another file which contains data that was taken at certain of these 87 positions. i.e.:
37 125
42 175
86 142
where the first... (1 Reply)
Hi
I am using the following command to delete a line from the file by line number:
line_number=14
sed "${line_number}d" inputfilename > newfilename
Is there a way to modify this command to specify the range of lines to be deleted, lets say from line 14 till line 5 ?
I tried using the... (5 Replies)
Hi,
I have a file as below
This is the line one
This is the line two
<\XMLTAG>
This is the line three
This is the line four
<\XMLTAG>
Output of the SED command need to be as below.
This is the line one
This is the line two
<\XMLTAG>
Please do the need to needful to... (4 Replies)
Hi all,
I have a file called "text.cpp" with the first line of "1"
afterwards I tried in Ubuntu to type the following
sed '12iasdasdasdasdsad' test.cpp > output.txt
however when I tried to see the result of output.txt
#cat output.txt
1
why is the line 12 is not updated to the... (6 Replies)
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
LEARN ABOUT ULTRIX
nl
nl(1) General Commands Manual nl(1)Name
nl - line numbering filter
Syntax
nl [-h type] [-b type] [-f type] [-v start#] [-i incr] [-p ] [-l num] [-s sep] [-w width] [-n format] [-d delim] file
Description
The command reads lines from the named file or from the standard input, if no file is named, and reproduces the lines on the standard out-
put. Lines are numbered on the left in accordance with the command options in effect.
The command views the text it reads in terms of logical pages. Line numbering is reset at the start of each logical page. A logical page
consists of a header, a body, and a footer section. Empty sections are valid. Different line numbering options are independently avail-
able for header, body, and footer. For example, you can elect not to number header and footer lines while numbering blank lines in the
body.
The start of logical page sections is signaled by input lines containing nothing but the following delimiter characters:
Line contents Start of
::: header
:: body
: footer
Unless otherwise specified, assumes that the text it is reading is in the body of a single logical page.
Options
Command options may appear in any order and may be intermingled with an optional file name. Only one file may be named.
-b type Specifies which logical page body lines are to be numbered. The following are recognized types and their meaning: a,
number all lines; t, number lines with printable text only; n, no line numbering; pstring, number only lines that con-
tain the regular expression specified in string.
The default type for logical page body is t (text lines numbered).
-h type Same as -b type except for header. Default type for logical page header is n (no lines numbered).
-f type Same as -b type except for footer. Default for logical page footer is n (no lines numbered).
-p Do not restart numbering at logical page delimiters.
-v start# The initial value used to number logical page lines. Default is 1.
-i incr The increment value used to number logical page lines. Default is 1.
-s sep The character used in separating the line number and the corresponding text line. Default sep is a tab.
-w width The number of characters used for the line number. Default width is 6.
-n format The line numbering format. Recognized values are the following: ln, left justified, leading zeroes suppressed; rn,
right justified, leading zeroes suppressed; rz, right justified, leading zeroes kept. Default format is rn (right jus-
tified).
-l num The number of blank lines to be considered as one. For example, -l2 results in only the second adjacent blank being
numbered (if the appropriate -ha, -ba, or -fa option is set). Default is 1.
-d xx The delimiter characters specifying the start of a logical page section may be changed from the default characters (:)
to two user-specified characters. If only one character is entered, the second character remains the default character
(:). No space should appear between the -d and the delimiter characters. To enter a backslash, you must type two
backslashes (//).
Examples
nl -v10 -i10 -d!+ file1
This command numbers file1 starting at line number 10 with an increment of ten. The logical page delimiters are !+.
See Alsopr(1)nl(1)