I am writing a KornShell (ksh) script that is logging to a file. I am redirecting the output of one of my commands (scp) to the same file, but I would like to add a tab at the start of those lines in the log file if possible.
Is this possible to do?
EDIT: Also I should mention that the text I am redirecting is coming from stderr. My line currently looks like this:
scp -q ${wks}:${file_location} ${save_directory} >> ${script_log} 2>&1
Note: the below doesn’t work for
ksh(see this question for possible solutions).You probably can do something like
The idea is to process the output of the command with a stream editor like
sedin some manner. In this case, a tab will be added at the beginning of every line. Consider:I haven’t tested this in
ksh, but a quick web search suggests that it should work.Also note that some commands can write to both
stdoutandstderr, don’t forget to handle it.Edit: in response to the comment and the edit in the question, the adjusted command can look like
or, if you want to get rid of
stdoutcompletely,The technique is described in this answer.