hi guys.
im new to bash scripting so i need your help.
i got an assignment that im having trouble to deal with.
i got a bunch of .log files that some of them are "corrupt"
example for a "corrupt" log file:
2019-08-22T13:33:44.123456789 Hello
World
2020-01-01T11:22:33.123456789 late
i need to write a script that sort the .log files in a given path (also in the sub directories of the given path) and keep the content of the log file.
example on 3 log file:
1.log
2019-08-22T13:33:44.123456789 Hello
World
2020-01-01T11:22:33.123456789 late
2.log
2019-09-44T13:44:21.987654321 Simple line
3.log
2019-08-22T13:33:44.123456789 Hello
World 2
2020-01-01T11:22:33.123456789 late 2
the output needs to be:
2019-08-22T13:33:44.123456789 Hello
World
2019-08-22T13:33:44.123456789 Hello
World 2
2019-09-44T13:44:21.987654321 Simple line
2020-01-01T11:22:33.123456789 late
2020-01-01T11:22:33.123456789 late 2
Code:
my script so far:
#!/bin/bash
path=$1
if cd $path;then
output="$(find ${dir} -name "*.log" | xargs cat | tr -d '\0' | sort -n -k1,1 -k2,2 )"
echo "${output}"
(exit 0)
else
(exit 2);
fi
thanks in advance for all the helpers!!