Help me to understand.

Searches for a text file with the fewest words.

$ find -name "*txt" | xargs wc -w | sort -g | head -n 1 

How to display the contents of the found text file with numbered lines? cat -n ?

  • one
    Figas puzzles set admins. Not every coder can handle this. - Sergey
  • 3
    @Sergey, you probably won't believe it, but for a unix user, this β€œtask” is the level (relatively speaking) of a β€œkindergarten”. in one word: primitive. - aleksandr barakin
  • Thanks for help) find -name '* txt' | xargs wc -w | sort -g | head -n 1 | xargs cat -n - Mansur Nabiev
  • @Sergey, good trolling. - 0andriy

1 answer 1

options for issuing the contents of a file or stream with numbered lines:

  1. nl

    1. the contents of the specified file:

       $ nl Ρ„Π°ΠΉΠ» 
    2. the contents of the stream of lines:

       $ ΠΊΠ°ΠΊΠΈΠ΅-Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ | nl 
  2. cat

    1. the contents of the specified file:

       $ cat -n Ρ„Π°ΠΉΠ» 
    2. the contents of the stream of lines:

       $ ΠΊΠ°ΠΊΠΈΠ΅-Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ | cat -n 
  3. less

    1. the contents of the specified file:

       $ less -N Ρ„Π°ΠΉΠ» 
    2. the contents of the stream of lines:

       $ ΠΊΠ°ΠΊΠΈΠ΅-Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ | less -N 
  4. awk

    1. the contents of the specified file:

       $ awk '{ print FNR " " $0 }' Ρ„Π°ΠΉΠ» 
    2. the contents of the stream of lines:

       $ ΠΊΠ°ΠΊΠΈΠ΅-Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ | awk '{ print FNR " " $0 }' 
  5. perl

    1. the contents of the specified file:

       $ perl -pe '$_ = "$. $_"' Ρ„Π°ΠΉΠ» 
    2. the contents of the stream of lines:

       $ ΠΊΠ°ΠΊΠΈΠ΅-Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ | perl -pe '$_ = "$. $_"' 

you, as I understand it, the whole stream ends with the issuance of the file name . To apply any of the listed commands to it, you need to use the xargs program, which you have already used. for example, you can pass this name to the nl program like this:

 $ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°ΡŽΡ‰ΠΈΠ΅ имя Ρ„Π°ΠΉΠ»Π° | xargs nl 
  • And also grep and sed. - 0andriy
  • @AndyShevchenko, your answers are welcome here. This also applies to your other comment . - aleksandr barakin 9:46
  • I do not want to produce entities. The seeker will see. Applies to all topikstarter and them responsible. - 0andriy