Sponsored Content
Top Forums Shell Programming and Scripting How to add line numbers (multiples of 5: 0,5,10,15,20) to a text file? Post 302885197 by RavinderSingh13 on Friday 24th of January 2014 06:10:33 AM
Old 01-24-2014
Quote:
Posted by Yoda:
Also if required, add -n option to format (ln - left justified, leading zeroes suppressed):


Code:
nl -v0 -i5 -nln file
Hello Yoda,

Could you please explain the code.

Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add text to file at a certain line

I am trying to add a line of text just before the last line in a file. For example, if the last line of a file is "exit 0", I need to add a line of text just before that. Any ideas how I might do that? Thanks (5 Replies)
Discussion started by: TheCrunge
5 Replies

2. Shell Programming and Scripting

Need to add a comment line in a text file

Hi I need to add a comment line at the begining of a text file. The scenario is given below. 1. The number of servers that needs to be updated is around 80 2. The location of the text file in all the servers are the same including the file name. 3. The comment has to be added at the very... (2 Replies)
Discussion started by: orakhan
2 Replies

3. Shell Programming and Scripting

how to print out line numbers of a text file?

i have this text file name test.txt which contain : aaaaa bbb iiiiiiiiiiiii ccf ddaaa ddd and i need a script that can print out the line numbers using a while loop.. so when the script is run..it will have this: 1 2 3 any ideas? :) thanks guys (4 Replies)
Discussion started by: forevercalz
4 Replies

4. Shell Programming and Scripting

find 2 line numbers, grab text in between

hi, i have a large text file that I just want to extract the important information from. It will be a random number of lines but between two specific line numbers/markers. I was thinking I could get the line number for the first marker: Tablespace Percent Total Free Then get the line... (11 Replies)
Discussion started by: Da_Duck
11 Replies

5. Shell Programming and Scripting

how to add line numbers in text file

Hi all How to add line numbers in text file.. ex abcd cdef result 1. abcd 2. cdef thx in advance (4 Replies)
Discussion started by: suryanarayana
4 Replies

6. Shell Programming and Scripting

Add one text line in the head of the file

hello, how can I add one text line string at the line number one of a file. thankx, (5 Replies)
Discussion started by: Ahmed waheed
5 Replies

7. Shell Programming and Scripting

Add ; to every line in text file

Please help to add ; to every line in a text file i Have tired sed 's/$/ ; /g' > /tmp/drop_tables.sql but not working :( Thanks (2 Replies)
Discussion started by: bluebird5m
2 Replies

8. Shell Programming and Scripting

sed add after line x new text from file

I've been playing with sed, trying to get it to insert the contents of somefile.txt after line 13 on anotherfile.txt. I tried searching for a line with regex and attempting to insert something on the next line with: find ./anotherfile.txt -type f -exec sed -i -e '/^dog/cat/' {} \; but it... (2 Replies)
Discussion started by: unclecameron
2 Replies

9. Shell Programming and Scripting

how to add text into the last line of text file

I need help with insert text to the last line of text file with echo command I know can do something like echo "i4\n$logtext\n.\nwq" | ex -s $file can insert to first line, but how can i change this code in order to insert to the last line of text file? please help, thank you :( (2 Replies)
Discussion started by: gavin_L
2 Replies

10. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies
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 Also
       pr(1)

																	     nl(1)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy