mlcarey1959
asked on
How do I combine several shell commands on one line?
for f in *.c *h; do echo >> $$f; done
tail -1 $$ff | od -An -t -oC -w1 | tail -1 | grep -c "012"
How do I combine these two commands?
tail -1 $$ff | od -An -t -oC -w1 | tail -1 | grep -c "012"
How do I combine these two commands?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Let me clear your requirement. You want to
append the output of
tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012"
into $f
such as
append the output of
tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012"
into $f
such as
for f in *.c *h; do echo `tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012"` >> $f; done
ASKER
I need to loop through some source files to check for a new line character at the end of the file and append a new line if one does not exist.
for f in *.c *.h; do if test (tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012") == 0 then echo >> "$$f" fi; done
for f in *.c *.h; do if test (tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012") == 0 then echo >> "$$f" fi; done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This does not work as is.
for f in *.c *.h; do [[ tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012" ]] && echo >> "$f" fi; done
conditional binary operator expected
syntax error near `-1'
for f in *.c *.h; do tail -1 $f | od -An -t oC -w1 | tail -1 | grep -c "012" || echo >> "$f"; done
This prints 0 if the file does not have a new line character and appends a new line character to the file.
It should only append the new line character.
for f in *.c *.h; do [[ tail -1 $f | od -An -t -oC -w1 | tail -1 | grep -c "012" ]] && echo >> "$f" fi; done
conditional binary operator expected
syntax error near `-1'
for f in *.c *.h; do tail -1 $f | od -An -t oC -w1 | tail -1 | grep -c "012" || echo >> "$f"; done
This prints 0 if the file does not have a new line character and appends a new line character to the file.
It should only append the new line character.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works
for f in *.c *.h; do [[ $( tail -1 $f | od -An -t oC -w1 | tail -1 | grep -c "012") ]] && echo >> "$f"; done
for f in *.c *.h; do [[ $( tail -1 $f | od -An -t oC -w1 | tail -1 | grep -c "012") ]] && echo >> "$f"; done
ASKER
no reason
Open in new window