0

How to access a file with su and search a pattern

su - root exec cat /home/root/file1.txt | grep pattern search 

Getting the below error when try to find patterns

**script: write :no space left on device **
  • It looks like you are out of space, try df -h . in the directory where you tried the above and look at Use% if it's at 100 you probably need to free some space. – A.Danischewski Sep 6 at 12:36
  • 2
    Btw, what is the idea behind cat file | grep pattern instead of grep pattern file? – Philippos Sep 6 at 12:45
  • @BethMckey What Philippos is asking is why don't you skip the cat which is useless and just complicates the command? They are well aware of the difference. – Kusalananda Sep 6 at 13:28
  • Im Sorry ! The only req is file1 has 100 lines & i need the line that matches the pattern. Even if i use grep pattern file ,the result appended t o another file has entire 100 lines. – Beth Mckey Sep 6 at 13:41
1

su - root grep pattern /home/root/file1.txt will do it. "no space left on device" is related to some other part of your script which tries to write data to an already full storage device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.