Parsing of Char and Numeric in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing of Char and Numeric in a file
# 1  
Old 11-04-2015
Parsing of Char and Numeric in a file

Hi All,

i'm working on some report and currently have this plain text file generated.

Code:
server_name1|sdfd1deal      |        1048572|        1040952|    99|      207|        1|       1
server_name1|dba1dbs        |       83886048|       40730796|    48|     5762|    22764|       8
server_name1|dbsd1phpal     |      503316320|       38609208|    07|     1087|      535|      40
server_name1|dbsd1dbsdl     |      199229388|       59869752|    30|      120|     6322|      13
server_name1|dbsd1deal      |      534773604|       50339708|    09|     8048|    21015|      39
server_name1|dbsd1eal       |      511704944|       84434568|    16|      524|      386|      36
server_name1|dbsd2dbsdl     |       94371828|       31457264|    33|       24|        4|       3
server_name1|dbsd3dbsdl     |      125829104|       27361264|    21|       27|        5|       4
server_name1|dbsd4dbsdl     |      157286380|       69732856|    44|       35|      364|       5
server_name1|dbsd5dbsdl     |       62914552|       36914328|    58|       11|        3|       2
server_name1|rootdbs1       |        2097148|        2072792|    98|     1116|    36319|       1


I want to convert it into HTML and got this code.

Code:
  {print "<tr>"
    for(i=1;i<=NF;i++)
        print "<td>" $i"</td>"
    print "</tr>"

My problem is the numeric columns shows left justified. I want all the columns to be right justified.

thanks in advance for anyone who can help.

This is currently in AIX, using ksh shell.

Fe

Last edited by Scrutinizer; 11-06-2015 at 01:06 AM..
# 2  
Old 11-04-2015
The easiest is to add CSS style once
Code:
<!DOCTYPE html>
<html>
<head>
<tittle>"Title Here"</title>
<style>
td { text-align:right; }
</style>
</head>

or to add at each td
Code:
"<td align=\"right\">"$i"</td>";

# 3  
Old 11-04-2015
Thanks.. i stand corrected.

Here's what i want...

String values should be left justified.
Numeric values should be right justified.

It's working, but the "String" values are also now right justified instead of Left justified.
# 4  
Old 11-06-2015
Code:
awk -F"|" '
    BEGIN{
        tda="<td align=\"right\">"
        tdo="<td>"
        tdc="</td>"
        
    }
    {
        print "<tr>"
        for(i=1;i<=NF;i++)
            print (($i == $i+0) ? tda : tdo) $i tdc
        print "</tr>"
    }
' fedora132010.file

# 5  
Old 11-08-2015
Thank you very much. It's working now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a numeric & special char to end of the first line

Need to add a numeric & special char to end of the first line Existing file: 12-11-16|11 2016 Jan 12:34:55|03:55| 13-10-16|10 2016 Jan 12:34:55|03:55|12-11-16|11 2016 Jan 12:34:55|03:55| 14-10-16|19 2016 Jan 12:34:55|03:55|13-11-16|11 2016 Jan 12:34:55|04:55| 15-10-16|18 2016 Jan... (11 Replies)
Discussion started by: Joselouis
11 Replies

2. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

3. UNIX for Dummies Questions & Answers

Find and Replace random numeric value with non-numeric value

Can someone tell me how to change the first column in a very large 17k line file from a random 10 digit numeric value to a non numeric value. The format of lines in the file is: 1702938475,SNU022,201004 the first 10 numbers always begin with 170 (6 Replies)
Discussion started by: Bahf1s
6 Replies

4. Shell Programming and Scripting

Converting Char to Numeric

HI, Here I have the following output and want to do some mathematical calculation on C2 & C3 column. c1 c2 c3 c4 c5 l1 1-oct 12:30:01 12:35 abc xyz l2 1-oct 14:20:01 14:35 def ... (5 Replies)
Discussion started by: dear_abhi2007
5 Replies

5. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. Shell Programming and Scripting

Parsing X char from right to left

I am new to bash scripts I need something quite easy to do in VBS, When I wanted to get the first 5 chars I used funcition right(5,strGet) how can I do the same in bash? I am trying to get the MAC address in Ubuntu I have done so far ifconfig wlan2 | grep HWaddr | awk '{print $5}' | sed -e... (3 Replies)
Discussion started by: 4scriptmoni
3 Replies

8. Shell Programming and Scripting

Parsing char string

I am stumped! I need to parse an input parameter to a script that has the form '-Ort'. I basically need 'O', 'r' and 't', i.e. the individual characters in the string parsed. Since there are no delimiters, I don't know how awk could do this. Can someone tell how to do this, this should be a... (5 Replies)
Discussion started by: ALTRUNVRSOFLN
5 Replies

9. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

10. Shell Programming and Scripting

How to check a column contain numeric or char data type ??

I have a file called clientname_filename.csv whose contents are like col1|col2|col3|col4| 510|abc|xxx|450| 510|abc11|yyy|350 510|pqr99|zzz| 670 512|222|439|110 Here i have check the contents of column for data type. i have a constraints that col1 always contain Numeric value column 2... (12 Replies)
Discussion started by: jambesh
12 Replies
Login or Register to Ask a Question