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
3
  • 1
    Why not append -------------------------------------- randomText instead? Commented Jul 15, 2013 at 19:06
  • notice how the last one does not have ----------------- at the end. I have some complex loop going on in my shell script that needs formatting. I just simplified the question to just a general idea of whether that was possible Commented Jul 15, 2013 at 19:09
  • 2
    printf, fmt, pr, indent, [nt]roff, tbl, and many other, along with other scripting tools (awk, perl, sed, even ed), all are capable of various types of formatting. You might need to better specify exactly what kind of thing you're trying to do... Commented Jul 15, 2013 at 19:38

2 Answers 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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.