Uniform Spacing in the message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Uniform Spacing in the message
# 1  
Old 10-18-2016
Uniform Spacing in the message

Hello,

I am running a script which sends an output as an email; I am having issues with the spacing being not uniform in the message. Snippet of the code and email message below:
Code:
 if [[ $Backup == '' ]] then echo "$Hostname\tMISSING\tHMCBackup" >> $BackupMsg
      else if [[ $Backup > $Current ]] then echo "$Hostname\tGood\tHMCBackup" >> $BackupMsg
      else if [[ $Backup < $Current ]] then echo "$Hostname\tStale\tHMCBackup" >> $BackupMsg; fi; fi; fi; done < $SupportedHosts

Email/Output

Code:
fcop23Stale	HMCBackup
fcop24MISSING	HMCBackup
fcop25MISSING	HMCBackup
fcopc6MISSING	HMCBackup
ecopc22	Stale	HMCBackup
ecopc23	Stale	HMCBackup
ecopc24	MISSING	HMCBackup
ecopc25	MISSING	HMCBackup
ecopc26	MISSING	HMCBackup


I would like the whole message to be like

Code:
ecopc24	MISSING	HMCBackup
ecopc25	MISSING	HMCBackup
ecopc26	MISSING	HMCBackup


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules (including desired output)!

Last edited by RudiC; 10-18-2016 at 11:47 AM.. Reason: Added CODE tags.
# 2  
Old 10-18-2016
If partial script shown is part of a loop, try:
Code:
while read Hostname Backup Current
do
if [[ $Backup == '' ]] then
   printf "$Hostname\tMISSING\tHMCBackup\n"
else
   if [[ $Backup > $Current ]]
   then
      printf "$Hostname\tGood\tHMCBackup\n"
   else
      if [[ $Backup < $Current ]]
      then
         printf "$Hostname\tStale\tHMCBackup\n"
      fi
   fi
fi
done < $SupportedHosts | expand > $BackupMsg

# 3  
Old 10-18-2016
You may want to look at the 'tabs' command.

This controls the default number of spaces.
# 4  
Old 10-18-2016
Hello rdrtx1,

I tried your code and I still get the same output.
# 5  
Old 10-18-2016
number of hostname characters throwing off tab spacing

your issue is with the number of characters in your hostname (i.e, fcop23 has 6 and ecopc22 has 7) that is throwing off the tab spacing since tab is placed in relation to the last character of the word preceding it.

change this
Code:
echo "$Hostname\tMISSING\tHMCBackup" >> $BackupMsg

to
Code:
echo "$Hostname,MISSING,HMCBackup" | tr ',' '\t' >> $BackupMsg

# 6  
Old 10-18-2016
Well, it is giving the output as below without any spaces

Code:
fcop23\Stale\HMCBackup
ecopc23\Stale\HMCBackup

no spaces at all

Last edited by rbatte1; 10-26-2016 at 11:05 AM.. Reason: Added CODE tags
# 7  
Old 10-18-2016
What happens if you precede the command with
Code:
tabs=15

which should set tab positions every 15 characters?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fastest alternatives to flattening a non-uniform nested array with regex?

Hello, I'm looking at simplfying a function that flattens an array, it uses recursion and filters objects by type but this seems to be a waste of resources to me at least, using conditionals like this seems like a bad idea. The array can be a generic type, int, string, float but not some... (2 Replies)
Discussion started by: f77hack
2 Replies

2. Shell Programming and Scripting

Fill in missing rows with zero to have uniform table

Hello, I have two files of same structure except some rows are missing randomly in each file. How do I fill the missing rows to have the exact ID column (S01 ~ S96) and rest columns filled with "0" with awk? The purpose of this step is to join the two files side by side. The closest thread is... (17 Replies)
Discussion started by: yifangt
17 Replies

3. AIX

Uniform LUN size

Hi, Is there any advantage is making all my storage LUNS ( hdisk ) of uniform size. Currently the LUN's are having different size () eg: 50G / 60G / 75G etc ). I am planning for a storage migration....so should i go for uniform lun size or with current LUN size pattern ? Regards, jibu (3 Replies)
Discussion started by: jibujacob
3 Replies

4. Shell Programming and Scripting

How can I format a text file into uniform columns?

I have a file : e.g. Charles Dixon Age 23 Hometown Darlington Postcode DL1 2DC Fred Bixton Age 34 Hometown Leeds Postcode LS1 5XS Jim Davis Age 48 Hometown Cardiff CF2 8YY Is it possible to format this file into uniform columns using, say, the spaces as... (11 Replies)
Discussion started by: bigbuk
11 Replies

5. UNIX for Dummies Questions & Answers

Help with the spacing

while IFS="" read r; do printf "XXX\t%s\n" "$r" done < test1.txt > test.txt The issue is, XXX wud be a dummy column/row added to the file..But i want this XXX column to be a separated as a TAB Delimiter it should be something like XXX 1 XXX 2 (3 Replies)
Discussion started by: saggiboy10
3 Replies

6. Shell Programming and Scripting

Searching for strings amongst non-uniform data

Hi Guys, I have a source file which contains significant strings amongst a lot of dross in non-uniform format, I'd like to search the input file for any examples of data from my reference file, and then output any matches to a list (text file). I've made something that achieves this, it's... (4 Replies)
Discussion started by: gazza86
4 Replies

7. Shell Programming and Scripting

uniform and same result whois command line

I am looking for a free whois lookup tool or some "scripting help" that will give uniform result for whois lookup from the linux command line. Currently: whois of a .co.nz domain results nameserver as follows. ns_name_01: ns1.domain.co.nz ns_name_02: ns2.domain.co.nz While that of a .net... (5 Replies)
Discussion started by: anilcliff
5 Replies

8. Shell Programming and Scripting

reformating non-uniform strings

I have a set of free-form phone numbers that are not uniform and I want to reformat them into a standard uniform string. These are embedded at the end of a colon seperated file built by a large nawk + tr piping like such: XXXXX:YYYYY:ZZZZZ:(333)333-3333x33333 XXXXX:YYYYY:ZZZZZ:x44444... (9 Replies)
Discussion started by: lordsmiter
9 Replies

9. Shell Programming and Scripting

Uniform length for all the lines in file

Hi, I have a file with different width for each line. like first line with 45characters and second line of 30 characters. But I want to make all the lines to 45 characters in file. Appreciate your inputs Thanks Arun: (1 Reply)
Discussion started by: arund_01
1 Replies

10. Shell Programming and Scripting

spacing problem

Hi guys, I have this little code: for directory in / $(echo $path | tr '/' ' ' ) do cd $directory echo "$(ls -ld | cut -c2-10 | sed 's/.\{3\}/& /' | sed 's/.\{7\}/& /' | sed 's/.\{1\}/& /g')" " $directory" done The output of this will be showing the permissions with spaces so it will... (2 Replies)
Discussion started by: darkhider
2 Replies
Login or Register to Ask a Question