Search code examples
unixsedterminalls

ls -l and sed are both printing output but i only need the latter to do so


I have to check the user permissions that have rwx, of all files using sed. What i have done: ls -l | sed '/^-rwx/p' - which gives me the following output:

-rwxr--r-- 1 myuser domain users 145 May 16 14:31 1.sh 

-rwxr--r-- 1 myuser domain users 145 May 16 14:31 1.sh

-rwxr--r-- 1 myuser domain users 185 May 16 16:50 2.sh

-rwxr--r-- 1 myuser domain users 185 May 16 16:50 2.sh

-rw-r--r-- 1 myuser domain users  13 May 16 14:31 compiler.c

-rw-r--r-- 1 myuser domain users   2 May 16 14:28 s.txt

I'm assuming that both ls and sed are printing their outputs. With grep it works fine and only returns 1.sh and 2.sh which is correct, but it's specified to be done with sed in the exercise.


Solution

  • I think you can use the sed opts -n

    -n, --quiet, --silent
        suppress automatic printing of pattern space 
    

    So it would be ls -l | sed -n '/^-rwx/p'