Printing a specific number of spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing a specific number of spaces
# 1  
Old 10-03-2016
Printing a specific number of spaces

when given a file name, im looking for the most efficient way to turn each letter of the file name into spaces.

for instance, the way im thinking of going about this is this:

Code:
MYFILE=check_disks.sh
CHANUM=$(echo ${MYFILE} | awk '{ print length }')
printf '%s\n' $CHANUM

as you can see here, i have about 3 commands that i believe can be combined into one. and im pretty sure the last printf command wouldn't work.
# 2  
Old 10-03-2016
Quote:
Originally Posted by SkySmart
when given a file name, im looking for the most efficient way to turn each letter of the file name into spaces.

for instance, the way im thinking of going about this is this:

Code:
MYFILE=check_disks.sh
CHANUM=$(echo ${MYFILE} | awk '{ print length }')
printf '%s\n' $CHANUM

as you can see here, i have about 3 commands that i believe can be combined into one. and im pretty sure the last printf command wouldn't work.
I must be missing the point. You show us a very inefficient script that uses two shells and an awk to print the number of characters in the value of a shell variable. I do not understand how this relates to turning each individual letter (which presumably does not include underscores and periods [and digits, but there aren't any digits in the given sample input]) into an unspecified number of <space> characters.

Please give us a clear specification of what you are trying to do, and tell us what operating system and shell you're using.
# 3  
Old 10-04-2016
Quote:
Originally Posted by Don Cragun
I must be missing the point. You show us a very inefficient script that uses two shells and an awk to print the number of characters in the value of a shell variable. I do not understand how this relates to turning each individual letter (which presumably does not include underscores and periods [and digits, but there aren't any digits in the given sample input]) into an unspecified number of <space> characters.

Please give us a clear specification of what you are trying to do, and tell us what operating system and shell you're using.
how do i print a specific number of spaces, which is equal to the number of characters in a name.

say a user specifies the name: check_disks.sh

there are 14 characters in the name "check_disks.sh".

i want to now print 14 spaces.
# 4  
Old 10-04-2016
You mean like:
Code:
printf '%*s' ${#MYFILE} ''

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-04-2016
Try also
Code:
echo "${A//?/ }"

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. Shell Programming and Scripting

Print a specific number of spaces

i'm looking for a command that allows me to print a specific number of spaces which i will provide. something as simple as: spaces=4 printf " " * $spaces i'm looking for somethign that'll allow me to print a specific amount of spaces on a line. can awk be used for this? (4 Replies)
Discussion started by: SkySmart
4 Replies

2. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

3. Shell Programming and Scripting

print - for printing whole line, but delimeters are changed to spaces

Hi consider the source file R|field1|field2 using the print statement in awk prints it as R field1 field2 Is there an easier way to print the whole line in its original format (i.e. with | delimiters) than doing print $1"|"$2"|"$3 ?? Thanks Storms (1 Reply)
Discussion started by: Storms
1 Replies

4. Shell Programming and Scripting

Printing Number of Fields with the line number

Hi, How to print the number of fields in each record with the line number? Lets saw I have 3212|shipped|received| 3213|shipped|undelivered| 3214|shipped|received|delivered I tried the code awk -F '|' '{print NF}' This gives me ouput as 3 3 4 (5 Replies)
Discussion started by: machomaddy
5 Replies

5. Shell Programming and Scripting

Replace spaces at a specific Location

Hello All, I have a comma separated file which needs to be loaded to the database. But, I need to trim the white spaces for a specific column before its loaded. Below is the sample line from the input file: 690,690,0575,"01011940","01011940", , , , , ,36720,36722,V2020,V2999,... (6 Replies)
Discussion started by: Praveenkulkarni
6 Replies

6. Shell Programming and Scripting

determine the number of spaces

Here is a weird question :) i am trying to create a script written in bash that will create configuration files for nagios. As some of you aware is has to be written in the below format: define service{ option1 value1 option2 value2... (6 Replies)
Discussion started by: ppolianidis
6 Replies

7. Shell Programming and Scripting

Merge 2 columns/remove specific spaces

Hi, I have a requirement to remove certain spaces from a table of information, but I'm unsure where to start. A typical table will be like this: ABCDE 1 Elton John 25 12 15 9 3 ABCDE 2 Oasis 29 13 4 6 9 ABCDE 3 The Rolling Stones 55 19 3 8 6The goal is to remove only the spaces between... (11 Replies)
Discussion started by: danhodges99
11 Replies

8. UNIX for Dummies Questions & Answers

grep any number of spaces

which one of the following is the correct expression to ignore line with multiple spaces after any string cat file | grep -v "xyz *$" or cat file | grep -v "xyz*$" do i need "*" to specify the sapce or " *" will do? (2 Replies)
Discussion started by: manishma71
2 Replies

9. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

10. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies
Login or Register to Ask a Question