Filling tab space with dots or dashes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Filling tab space with dots or dashes
# 1  
Old 05-10-2013
Filling tab space with dots or dashes

Hey Guys & Gals !

My script is creating a numbered list and I would like to have the numers and
results spaced apart by a tab.

Now to make sure it is clear which number corresonds with which outcome, I would like to have the tab space filled with dashes.

Anyone able to tell me if this is possible ?

Current;
Code:
 
for i in {1..50} ; do echo -en "$i \t" && script blah blah
1     output
2     output
3     output
4     output

Desired;
Code:
for i in {1..50} ; do echo -en "$i \t" && script blah blah
1----output
2----output
3----output
4----output

# 2  
Old 05-10-2013
How about replacing the echo ... by printf "%-4d" "$i"?
Still spaces but not so many.
# 3  
Old 05-12-2013
Hey there,

Thanks for the response, what I was hoping to achieve was to avoid a larger
indentation when the counter reaches double values.

For instance, when just using \t it is printed as I would like;
Code:
 
for i in {1..15} ; do echo -en "$i\t" && echo "test" ; done
1	test
2	test
3	test
4	test
5	test
6	test
7	test
8	test
9	test
10	test
11	test
12	test
13	test
14	test
15	test


I tried using sed to replace [\t] with dashes, but this does not work as I would like as it (obviously) causes an space displacement for the double character counter which I am trying to avoid;

Code:
 
for i in {1..15} ; do echo -en "$i\t" | sed 's/[\t]/--->/' && echo "test" ; done
1--->test
2--->test
3--->test
4--->test
5--->test
6--->test
7--->test
8--->test
9--->test
10--->test
11--->test
12--->test
13--->test
14--->test
15--->test


Ah well, will continue teh googelz Smilie

Last edited by TAPE; 05-12-2013 at 07:02 AM..
# 4  
Old 05-12-2013
You could try trivial things like:
Code:
printf "%5d---%s\n" "$i" "test"
        or
printf "%05d---%s\n" "$i" "test"

If it is important that the numbers be aligned to the left of the field, you could try:
Code:
printf "%d%*.*s%s\n" $i $((8 - ${#i})) $((8 - ${#i})) "--------" "test"

which will work with any POSIX conforming shell (including a recent bash or a Korn shell with a version of 1993 or later) for values of i from 0 through 99999999.
# 5  
Old 05-12-2013
Thanks !

Using
Code:
printf "%2---%s\n" "$i" "test"

Code:
for i in {1..15} ; do printf "%2d---> %s\n" "$i" "test" ; done
 1---> test
 2---> test
 3---> test
 4---> test
 5---> test
 6---> test
 7---> test
 8---> test
 9---> test
10---> test
11---> test
12---> test
13---> test
14---> test
15---> test

is already looking better, would prefer the numbers to be left aligned, but think can live with this.

Thanks for the response !
# 6  
Old 05-12-2013
Quote:
Originally Posted by TAPE
would prefer the numbers to be left aligned, but think can live with this.
Code:
$ for i in $(seq -w 01 12) ; do echo "$i ---> test" ; done
01 ---> test
02 ---> test
03 ---> test
04 ---> test
05 ---> test
06 ---> test
07 ---> test
08 ---> test
09 ---> test
10 ---> test
11 ---> test
12 ---> test

# 7  
Old 05-12-2013
What about
Code:
$ dashes="-----"
$ for i in {8..12} ; do echo $i${dashes:1:4-${#i}}">test" ; done
8--->test
9--->test
10-->test
11-->test
12-->test

This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace space by tAB

My file looks like 3 33 210.01.10.0 2.1 1211 560 26 45 1298 98763451112 15412323499 INPUT OK 3 233 40.01.10.0 2.1 1451 780 54 99 1876 78787878784 15423210199 CANCEL OK Aim is to replace the spaces in each line by tab Used: sed -e 's/ */\t/g' But I get output like this... (3 Replies)
Discussion started by: sa@@
3 Replies

2. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

3. Shell Programming and Scripting

how to keep tab from being converted to space

Hi, I want to read lines from a file, and I'm using two methods 1 use while read line do done<filename 2 use line=`sed -n '3p' filename` however, in both of them, I notice that the tab between fields are automatically converted to space because I want to use awk over the... (10 Replies)
Discussion started by: esolvepolito
10 Replies

4. UNIX for Dummies Questions & Answers

Filling a tab-separated file with known missing entries in columns

Hello all, I have a file which is tab separated like that: PHE_205_A TIP_127_W ARG_150_B MET_1150_A TIP_12_W VAL_11_B GLU_60_A TIP_130_W ARG_143_B LEU_1033_A TIP_203_W ARG_14_B SER_1092_A TIP_203_W THR_1090_A TIP_203_W SER_1092_A TIP_25_W ... (6 Replies)
Discussion started by: TheTransporter
6 Replies

5. UNIX for Dummies Questions & Answers

Delimiter: Tab or Space?

Hello, Is there a direct command to check if the delimiter in your file is a tab or a space? And how can they be converted from one to another. Thanks, G (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

6. Shell Programming and Scripting

Awk to find space and tab.

Wants to print line when there exist leading or trailing space or tab in fields 2,3 and 5 The below code prints all lines in file even if they dont have leading and trailing space or tab. nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^*" || $i ~ "*$")}}1' file file Ouput required: ... (5 Replies)
Discussion started by: pinnacle
5 Replies

7. UNIX for Advanced & Expert Users

diff command filling /var filesystem space

Hi, I am using diff command to check difference between two files.Both files are very big and when i execute this command /var temp space is filled up almost 99%. Can any one please tell me is there any way i can specify directory name which has more space so that diff can use that dir for... (2 Replies)
Discussion started by: ukatru
2 Replies

8. Shell Programming and Scripting

need help in tab space !

i have a commad that display the total each directory size in KB.Below the commad and o/p: ls -ltr | grep ^d | awk '{print $9}' | xargs du -sk output: what i want is the proper tab space b/w value and dir.? how to get that. thanks in advance (10 Replies)
Discussion started by: ali560045
10 Replies

9. Shell Programming and Scripting

How to echo a <tab> space?

I've tried this: echo "${bold}User${norm} : u"\t"${bold}All Users ${norm} : a\t" and i got this output: Specific User : u\tAll User: a\t (14 Replies)
Discussion started by: laila63
14 Replies

10. UNIX Desktop Questions & Answers

replace tab with space

How do I replace a tab with a space in scripts using sed/awk ? (1 Reply)
Discussion started by: avnerht
1 Replies
Login or Register to Ask a Question