Text Alignment Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text Alignment Problem
# 1  
Old 07-10-2009
Question Text Alignment Problem

Dear Friends,

I've one file "sample.log" with the below comma separated lines:

Code:
BOND_FORWARD,0 succeeded,0 failed.
EQUITY_FORWARD,0 succeeded,0 failed.
FRA,12 succeeded,0 failed.
OPTION_BAR,16 succeeded,0 failed.
OPTION_VAN,76 succeeded,0 failed.
RENTOPT_CAP_FLOOR,4775 succeeded,0 failed.
RENTOPT_BOP,0 succeeded,0 failed.
RENTOPT_SWP,2159 succeeded,4 failed.
REPO,250 succeeded,0 failed.
SWAP,53903 succeeded,0 failed.
VXHAND,0 succeeded,0 failed.

my intended out put should be, like below:

Code:
BOND_FORWARD            0 succeeded             0 failed.
EQUITY_FORWARD          0 succeeded             0 failed.
FRA                     12 succeeded            0 failed.
OPTION_BAR              16 succeeded            0 failed.
OPTION_VAN              76 succeeded            0 failed.
RENTOPT_CAP_FLOOR       4775 succeeded          0 failed.
RENTOPT_BOP             0 succeeded             0 failed.
RENTOPT_SWP             2159 succeeded          4 failed.
REPO                    250 succeeded           0 failed.
SWAP                    53903 succeeded         0 failed.
VXHAND                  0 succeeded             0 failed.

Below are my line of code:

Code:
tab_space=$(printf "\t\t";)
sed "s/,/$tab_space/g" sample.log

But the generated output is as below (not properly aligned):

Code:
BOND_FORWARD            0 succeeded             0 failed.
EQUITY_FORWARD          0 succeeded             0 failed.
FRA             12 succeeded            0 failed.
OPTION_BAR              16 succeeded            0 failed.
OPTION_VAN              76 succeeded            0 failed.
RENTOPT_CAP_FLOOR               4775 succeeded          0 failed.
RENTOPT_BOP             0 succeeded             0 failed.
RENTOPT_SWP             2159 succeeded          4 failed.
REPO            250 succeeded           0 failed.
SWAP            53903 succeeded         0 failed.
VXHAND          0 succeeded             0 failed.

Any help to correct my code would be much appreciated.
Thanks in advance / Mysore 101 Ganapati.

Last edited by vgersh99; 07-10-2009 at 12:39 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-10-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 11:46 AM ---------- Previous update was at 11:40 AM ----------

Code:
nawk -F, '
{
  for(i=1;i<=NF;i++)
     printf("%-25s%c", $i, (i==NF)?ORS:"")
}' myFile

# 3  
Old 07-10-2009
MySQL

Hi Vgersh99,

Thanks for opening my eyes,
Thanks for blowing your torch,
Thanks for your time and help,
Thanks for your working answer.
Smilie
Cheers~~/ Mysore 101 Ganapati.
A sound discretion is not so much indicated by never making a mistake as by never repeating it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alignment tool to join text files in 2 directories to create a parallel corpus

I have two directories called English and Hindi. Each directory contains the same number of files with the only difference being that in the case of the English Directory the tag is .english and in the Hindi one the tag is .Hindi The file may contain either a single text or more than one text... (7 Replies)
Discussion started by: gimley
7 Replies

2. Shell Programming and Scripting

Add Blank Spaces in text, to perform beter alignment of the string

Hi Guru, I need some advice on how to add blank spaces to the code, rather than me just adding <space-bar spaces> which does not work. Current output of the code File System Backed Up - ALL_LOCAL_DRIVES Daily - Incremental Backup Schedule - 1 Month Retention • 7pm - PRD... (2 Replies)
Discussion started by: Junes
2 Replies

3. Shell Programming and Scripting

Inserting IDs from a text file into a sequence alignment file

Hi, I have one file with one column and several hundred entries File1: NA1 NA2 NA3And now I need to run a command within a mapping aligner tool to insert these sample names into a sequence alignment file (SAM) such that they look like this @RG ID:Library1 SM:NA1 PL:Illumina ... (7 Replies)
Discussion started by: nans
7 Replies

4. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

5. Shell Programming and Scripting

Text qualifier issue causing data alignment problem

Hello Everyone, I have a csv file with text qualifier as "" and data similar to below: "1","abc","address1","US" "2","def","address1 "characters in double-quote" address2","IND" "3","ghi","address1","UK" In above example, for record 2, we have an issue as in column3 contains double... (2 Replies)
Discussion started by: AnkitSenghani
2 Replies

6. HP-UX

HP-UX text alignment

HI all, I tried to edit my files using HP-UX but my output tends to not align when I add another character in the files to edit my files i used the command is as follow chmod +w filename vi filename Help, :eek: (1 Reply)
Discussion started by: jasonhpwong
1 Replies

7. Shell Programming and Scripting

Output alignment problem

Hi Gurus, This is my raw data. How would I able to format this output into a better alignment? /dev/vg00/lvol5 /home 0.12 GB 0.02 GB 0.10 GB 19% /dev/vg00/misc /misc 28.43 GB 4.92 GB 23.51 GB 17% /dev/vg00/lvol6 /opt 8.25 GB 5.43 GB 2.82 GB 65% /dev/vgsap/ora10264 ... (10 Replies)
Discussion started by: superHonda123
10 Replies

8. Programming

how to round up a memory address(memory alignment problem)

Hi, I try to marshal a unsigned int and a char * into a buffer, and then unmarshal them later to get them out. I need to put the char * in the front and unsigned int at the end of the buffer. However, my system always give me "BUS ERROR". I am using Sun Sparcs Sloris 2.10. My code to marshal... (6 Replies)
Discussion started by: nj302
6 Replies

9. Solaris

Memory Alignment Problem on Sun Sparcs

Hi, I try to marshal a unsigned int and a char * into a buffer, and then unmarshal them later to get them out. I need to put the char * in the front and unsigned int at the end of the buffer. However, my system always give me "BUS ERROR". I am using Sun Sparcs Sloris 2.10. My code to marshal the... (1 Reply)
Discussion started by: nj302
1 Replies

10. UNIX for Dummies Questions & Answers

ls command alignment problem

With older Linux servers, the command: ls -al would output text that would have the filenames all lined up in the same column (the owner and group names were truncated to produce a uniform right column). In newer distros (i.e. RHEL 3), the command will push the right column out when owners... (0 Replies)
Discussion started by: robf
0 Replies
Login or Register to Ask a Question