0
Thanks

A few words of thanks would be greatly appreciated.

SED - Numbering lines



  • Numbering lines (same as "cat -n file.txt")
    • sed = file.txt
  • The problem is that the display is effected on 2 lines. To set this as default:
    • sed = file.txt | sed 'N;s/\n/\t/'
  • Number the lines but display only the numbers of non-blank lines.
    • sed '/./=' file.txt | sed '/./N;s/\n/ /'
  • Counting the number of lines (same as "wc -l file.txt | awk '{ print $1 }'")
    • sed -n '$=' file.txt
  • Defining the line number containing a reason
    • sed -n '/Start/=' file.txt
  • The setting= "accepts only one address, to define the numbers of lines between 2 reasons, use the following syntax
    • sed -n '/start,/Fin/{=;d;}' file.txt
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

Published by . Latest update on by deri58.

This document, titled "SED - Numbering lines," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments