Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a tab character before external script output

Tags:

bash

shell

ubuntu

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 }'
like image 485
Smurker Avatar asked Dec 10 '13 10:12

Smurker


People also ask

How do you add a tab in a screenplay?

The tab character can be inserted by holding the Alt and pressing 0 and 9 together.

How do I add a tab to a bash script?

tab-insert (M-TAB) Insert a tab character.

How do you insert a tab at the beginning of each line in the list?

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.

How do I give a tab space in Linux?

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 do I echo a tab character in Bash?

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.


1 Answers

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/^/    /'
like image 169
Daniel Avatar answered Nov 15 '22 08:11

Daniel