So, i've got a shell script to automate some SVN commands. I output to both a logfile and stdout during the script, and direct the SVN output to /dev/null. Now i'd like to include the SVN output in my logging, but to seperate it from my own output i'd like to prepend a \t
to each line of the SVN output. Can this be done with shell scripting?
Edit Is this something i could use AWK for? I'll investigate!
Edit So, using AWK seems to do the trick. Sadly i can't get it to work with the svn commands though.
svn add * | awk '{ print "\t"$0 }'
Outputs without the prepended tab character. But if i run for example ls
ls -l | awk '{ print "\t"$0 }'
The directory is listed with a tab character in front of each line.
Edit Thanks @daniel! I ended up with this
svn add * 2>&1 | sed 's/^/\t/'
Might aswell note that awk works well for this, when used correctly
svn add * 2>&1 | awk '{print "\t"$0 }'
The tab character can be inserted by holding the Alt and pressing 0 and 9 together.
tab-insert (M-TAB) Insert a tab character.
If you want to make sure that Word inserts a tab character, simply press Ctrl+Tab. This will work any time in Word but is of the most use at the beginning of lines.
Using the awk Command With the help of the awk command, we can easily convert whitespaces to TAB characters. By default, AWK uses [ \t\n]+ as Field Separator (FS) and a space character as an Output Field Separator (OFS). In the command above, we're setting the TAB character as an Output Field Separator.
How to echo a tab in bash? Answer: In Bash script, if you want to print out unprintable characters such as tab, you need to use -e flag together with the echo command.
You can use Sed. Instead of redirecting the output of your SVN command to /dev/null
, you can pipe it to Sed.
svn ls https://svn.example.com 2>&1 | sed 's/^/ /'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With