I am working on a script that will process a .zip file received from clients. It is common in my job to want the contents of the .zip file received listed within a log file as a means of validation. I have been able to extract the list of files from my test files and insert the list of files within a log file.
I am now attempting to neaten the log file up by adding newline and tabs before the names of the extracted files in the log file. I have come closest with the commented line in the sample below but it only adds tabs to a single line of the output. I next thought about using SED but my poor knowledge of it just results in a blank line in the log file...
log_message "-------- Extracting files"
zipflist="`unzip -Z1 $file`"
log_message "Files found in received zip file..."
# log_message $'\n\t\t\t'"$zipflist"
log_message `sed '1 s/^/$'\t'"$zipflist"/' `
The "log_message" function passes strings to a file with a pre-pended date time.
Here is what the best results I have gotten look like so far:
2023-12-29 09:31:44: Files found in received zip file...
2023-12-29 09:31:44:
loremipsum.pdf
loremipsum.txt
dummy_report.xml
I would prefer the output to look like this:
2023-12-29 09:31:44: Files found in received zip file...
2023-12-29 09:31:44:
loremipsum.pdf
loremipsum.txt
dummy_report.xml
Is there a way this can be accomplished with SED, tr or other base utility in RHEL? I cannot install anything not company approved so I prefer to work with what I have. (Saves the hassle of approvals)
$(). You'll thank me the next time you need to use nested command substitution.