LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cat command -s , -n (https://www.linuxquestions.org/questions/linux-newbie-8/cat-command-s-n-4175451967/)

doug skillmore 02-27-2013 04:26 PM

cat command -s , -n
 
hi i wont bother anyone again today i promise. as you can tell i am doing homework

what is the difference between -s, -n when using cat command?


thank you again in advance

colucix 02-27-2013 04:48 PM

Well, as a general advice you should carefully read the man pages, especially when looking for options and their meaning. For example:
Code:

$ man cat
<scroll>
      -n, --number
              number all output lines

      -s, --squeeze-blank
              suppress repeated empty output lines
<omitted>

At this point some exercise is useful to test our understanding. For example I create a file with 4 lines (leaving two lines in the middle empty) using echo and redirection:
Code:

$ echo first line > file
$ echo >> file
$ echo >> file
$ echo fourth line >> file

Ok. Let's try with cat and its options:
Code:

$ cat file
first line


fourth line

The above is just the content of the file, as expected (a usage of cat - without options - is to print out the content of a file). Let's try our options:
Code:

$ cat -n file
    1  first line
    2
    3
    4  fourth line
$ cat -s file
first line

fourth line

Mirroring your question, what's the difference between -n and -s now? :jawa:

etech3 02-27-2013 04:52 PM

You did look at the help and man files right?

-n, --number >number all output lines
-s, --squeeze-blank >suppress repeated empty output lines


All times are GMT -5. The time now is 08:54 PM.