merging two command in one command
Hi ,
I have a file and it has some content . Now I want to check for some text in that file and if does not exist I want to append it . So I need to first grep and then do "echo "content" >> s.txt" . Is there any way to execute this two commands in a single command . Please let me know . regards Suman |
Hi,
I'm sure that is possible (awk comes to mind), but why the need for one command, it would complicate things (just my 2c). This grep something file || echo "text" >> file will do what you want. Short and elegant. The || is an OR statement, if grep doesn't find anything ("fails" if you want) the echo statement is executed. There is also the && (AND) command (do something if previous command is successful). Hope this helps. |
Like in
Code:
grep -v "some text" s.txt && echo "some text" >> s.txt P.S.: too slow ;D |
Do you mean something like:
Code:
grep -q content s.txt || echo content >> s.txt Evo2. PS. Much too slow! |
All times are GMT -5. The time now is 12:54 AM. |