Reputation: 685
I have a command:
find /etc -type f \( ! -perm /o=w \) -exec /usr/bin/ls -hastl '{}' \; -exec /usr/bin/md5sum '{}' \; > somefile.log
and this command creates such printout (i need to have no breaking line) :
...
4.0K -rw-r--r--. 1 root root 332 Oct 23 2012 /etc/xinetd.d/rsync
fd32314f3157aaf15712e6da7758060d /etc/xinetd.d/rsync
....
question: what I must add to this command to remove new line operation to get such result:
(...) is '-rw-r--r--. 1 root root 332 Oct 23 2012'
...
4.0K (...) /etc/xinetd.d/rsync >> fd32314f3157aaf15712e6da7758060d /etc/xinetd.d/rsync
...
Upvotes: 1
Views: 949
Reputation: 1894
Two join every pair of adjacent lines just pipe your output to awk 'NR%2{line=$0;next}{print line sep $0}' sep=" >> "
adjusting sep
to your need.
Addendum:
In response to the original author's comment I am going to explain some details of this solution:
awk
processes input record-wise, without further options that is line-by-line.
The (internal) variable NR
stores the current record's number. %
is the modulus operator, so NR%2
evaluates to 1
for odd line numbers and 0
for even line numbers. {...}
groups commands (so called 'action') to perform. Since 1
is considered "true" and 0
"false" the first action is only performed for odd line numbers. This action consists of two commands: First, the whole line ($0
) is stored in the variable line
and then the next
record is processed (without considering any other action). For even lines, this action is not performed, so the second action is considered. Since there is no expression before the {
the action is performed: the stored (i.e. previous) line
is concatenated with a variable called sep
and the current line ($0
). The resulting string is printed (and automatically appended by one new-line in the end). The value of sep
is handed to awk
as a parameter to make it easy to adjust it without messing with the script. Since awk
reads standard input and output without further arguments you can just pipe (|
) the output of your find to awk
(find ... -exec ... -exec ... | awk ... > ...
)
Upvotes: 1
Reputation: 1256
IMHO You can only execute one command with exec. A possible solution might be you execute "sh -c" so you can use pipes and similar:
With one newline at the end:
find /etc -type f -exec sh -c "/bin/ls -hastl '{}' | tr '\n' ' '" \; -exec /usr/bin/md5sum '{}' \;
without any newline:
find /etc -type f -exec sh -c "/bin/ls -hastl '{}' | tr '\n' ' '" \; -exec sh -c "/usr/bin/md5sum '{}'| tr -d '\n' " \;
Upvotes: 0
Reputation: 409136
How about a command such as
echo "$(ls -hastl '{}') >> $(md5sum '{}')"
Upvotes: 1