Aretai Posted March 5, 2007 Share Posted March 5, 2007 Hi, I have a problem with displaying unix commands output in php. I use SunOS5, php4. I try to put on the web content of the command usr/local/aretai/grep -irU /opt/users/aretai/test/projects/* This works - I get a list of the files some of them are binary so it's like: Binary file /opt/users/aretai/test/projects/test.txt matches Binary file /opt/users/aretai/test/projects/test1.txt matches Binary file /opt/users/aretai/test/projects/test2.txt matches Binary file /opt/users/aretai/test/projects/test3.txt matches Binary file /opt/users/aretai/test/projects/test4.txt matches Now I want to strip the unnecessary "Binary file" and "matches" in case they occur (sometimes they don't). I tried to do it with : echo "Binary file opt/users/test/projects/test.txt Matched" | sed "s/^.*aretai\([^ ]*\) .*/\1/" Yes I know it's only for the one file, but when I put it in the: shell_exec(" "Binary file opt/users/test/projects/test.txt Matched" | sed "s/^.*aretai\([^ ]*\) .*/\1/" "); I get error T_STRING... I tried diff things " 'Binary ... etc. I know it's necessary to escape single ' but how's with the "? thx for answer Aretai Link to comment https://forums.phpfreaks.com/topic/41309-output-from-unix-with-php/ Share on other sites More sharing options...
effigy Posted March 5, 2007 Share Posted March 5, 2007 You may need to use xargs, but try this: echo 'Binary file ... matches' | sed -e 's/^Binary file//' | sed -e 's/matches$//' Link to comment https://forums.phpfreaks.com/topic/41309-output-from-unix-with-php/#findComment-200150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.