0

from the command line to redirect an ouptput to another file I am aware that I can do something like this

$ echo randomText > file.md

I am also aware that, if I want to append the output to the end of the file, I can do something like this

$ echo randomText >>  file.md

Now if I cat the content of file.md I will see something like

randomText
randomText

Is there a way to format the output that is being sent to the file. Rather than appending to the end I am hoping to achieve something like this

randomText -----------------------------------  randomText
4

2 回答 2

1

To do this, I used printf to format the ouput that was being sent to the file.

printf "%10s", "------------------------------------------" > file.md

To append to the same line, yuou could use printf to tab it.

于 2013-07-16T12:55:19.530 回答
0

While going through loop you can try this

echo -ne "randomText" >> logfile
# some other actions
echo -ne "--------------------------------------" >> logfile
echo -ne "randomText" >> logfile

In logfile you can now find

randomText--------------------------------------randomText
于 2013-07-16T06:53:46.503 回答