Numbering lines

Last update on November 17, 2008 06:49 AM by deri58
Published by deri58

Sed - Numbering lines








Numbering lines (equat to "cat -n file.txt") sed = file.txt

The problem is that the display is effected on 2 lines. To set this default:

sed = file.txt | sed 'N;s/\n/\t/'

Number the lines but only the numbers of non-blank lines.

sed '/./=' file.txt | sed '/./N;s/\n/ /'

Counting the number of lines (equal to "wc -l file.txt | awk '{ print $1 }'")
sed -n '$=' fichier.txt

Defining the line number containing a reason

sed -n '/Début/=' fichier.txt


The setting= "accepts only one address, to define the numbers of lines between 2 reasons, use the following syntax

sed -n '/Début/,/Fin/{=;d;}' fichier.txt
Best answers for « Numbering lines » in :
[Sed] Delete one or more lines from a file Show [Sed] Delete one or more lines from a file Removing one (or several) line (s) of a file Syntax: sed '{[/]||[/]}d' sed '{[/][,][/]d' /.../=delimiters n = line number...
How to read a file line by line Show How to read a file line by line Intro Tips Bonus Intro One of the most common errors of learning scripts bash on GNU / Linux is to read a file line by line, is to use a loop "for" (for line in $ (cat file.txt) do. ..), which in this...
Generating random numbers with rand() ShowGenerating random numbers with rand() You may have noticed when using the rand() found in the standard library of C language, you often get unsatisfied by the results, they look the same. For example, when trying 5 random numbers in...
Google: Number of Results ShowGoogle: Number of Results Number Of Results When doing a research with Google search engine, you will get by default 10 results displayed on the results page. If you wish to extend the number of results on that page, there is an easy...
[Linux]Having a daily report of servers by mail Show[Linux]Having a daily report of servers by mail The monitoring and administration of Linux systems is a very difficult task when there is large number of interconnected servers, system resources and updates to each of them it,must...
Download Avira AntiVir Personal free for Linux / FreeBSD / OpenBSD / Solaris ShowFor Linux / FreeBSD / OpenBSD / Solaris Avira AntiVir PersonalEdition Classic is a very good and free antivirus which reliably protects your private computer against dangerous viruses, worms, Trojans, rootkits and costly dialers.
Download Random Number Generator Pro ShowRandom Number Generator Pro is a tool that generates a list of random numbers based on customizable criteria. You can choose the minimum and maximum limits and incrementing numbers. Limits can be positive or negative values. Advantage The...
NAT- Network address translation, port forwarding and port trigg ShowThe principle of NAT Network address translation or NAT was developed in order to respond to the shortage of IP addresses with IPv4 protocol (in time the IPv6 protocol will respond to this problem). In fact, in IPv4 addressing the number of...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...