Sponsored Content
Full Discussion: justifying the fields
Top Forums Shell Programming and Scripting justifying the fields Post 302163195 by quintet on Thursday 31st of January 2008 08:09:00 AM
Old 01-31-2008
i dont see the justications in ur message..
does this help?

awk '{printf ("%8s%8s%8s%8s%8s\n",$1,$2,$3,$4,$5);}' sample

Quote:
Originally Posted by shary
hi experts,
i just need a help that my script is generating the output which i will mentioned below but the fileds are not justified the alignment is disturbed.

0 8718 8718 0 8777
1 7450 7450 0 7483
2 5063 5063 0 5091
3 3840 3840 0 3855
4 3129 3129 0 3142
5 2400 2400 0 2419
6 2597 2597 0 2604
7 3055 3055 0 3078
8 4249 4249 0 4266
9 4927 4927 0 4957
10 8920 8920 0 8978
11 19567 19567 0 19675
12 15249 15249 0 15330
13 13930 13930 0 14015
14 13694 13694 0 13742
15 13066 13066 0 13122
16 12477 12477 0 12548
17 12791 12791 0 12855
18 13754 13754 0 13842
19 13181 13181 0 13259
20 12991 12991 0 13048
21 12435 12435 0 12484
22 13545 13545 0 13624
23 14584 14584 0 14656
total 235612 235612 0 236850

so at the end i just want the output in the correct format and justified like.
0 8718 8718 0 8777
1 7450 7450 0 7483
2 5063 5063 0 5091
3 3840 3840 0 3855
4 3129 3129 0 3142
5 2400 2400 0 2419
6 2597 2597 0 2604
7 3055 3055 0 3078
8 4249 4249 0 4266
9 4927 4927 0 4957
10 8920 8920 0 8978
11 19567 19567 0 19675
12 15249 15249 0 15330
13 13930 13930 0 14015
14 13694 13694 0 13742
15 13066 13066 0 13122
16 12477 12477 0 12548
17 12791 12791 0 12855
18 13754 13754 0 13842
19 13181 13181 0 13259
20 12991 12991 0 13048
21 12435 12435 0 12484
22 13545 13545 0 13624
23 14584 14584 0 14656
total 235612 235612 0 236850

so please kindly tell me that how i can justfied te filelds properly though shell script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

2. Shell Programming and Scripting

Add fields in different files only if some fields between them match

Hi everybody (first time posting here) I have a file1 that looks like > 1,101,0.1,0.1 1,26,0.1,0.1 1,3,0.1,0.1 1,97,0.5,0.5 1,98,8.1,0.218919 1,99,6.2,0.248 2,101,0.1,0.1 2,24,3.1,0.147619 2,25,23.5,0.559524 2,26,34,0.723404with 762 lines.. I have another 'similar' file2 > ... (10 Replies)
Discussion started by: murpholinox
10 Replies

3. UNIX for Dummies Questions & Answers

Set variables from fields in fields

Hi, This is my first post here and I am a newbie. :) I have a file that looks like this : Introduction:Intro_123.html Product definition:Prod_def.html System Setup:SSetup-64bit.html Setting up user accounts:Set_user_acc.html I tried to create a script that would output "The filename... (3 Replies)
Discussion started by: Joq
3 Replies

4. UNIX for Dummies Questions & Answers

Right justifying prompt data in bash

Hi, I have a custom prompt in Bash. However, I would like to further customise it so that it shows me the date and time. However, I would like this new addition to appear on the right side of the terminal window. The idea behind this is to "visually balance" some data on the right as most of... (2 Replies)
Discussion started by: vnayak
2 Replies

5. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

6. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

7. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

8. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

9. Shell Programming and Scripting

Print . in blank fields to prevent fields from shifting

The below code works great, kindly provided by @Don Cragun, the lines in bold print the current output. Since some of the fields printed can be blank some of the fields are shifted. I can not seem too add . to the blank fields like in the desired output. Basically, if there is nothing in the field... (10 Replies)
Discussion started by: cmccabe
10 Replies

10. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies
JOIN(1) 						    BSD General Commands Manual 						   JOIN(1)

NAME
join -- relational database operator SYNOPSIS
join [-a file_number | -v file_number] [-e string] [-o list] [-t char] [-1 field] [-2 field] file1 file2 DESCRIPTION
The join utility performs an ``equality join'' on the specified files and writes the result to the standard output. The ``join field'' is the field in each file by which the files are compared. The first field in each line is used by default. There is one line in the output for each pair of lines in file1 and file2 which have identical join fields. Each output line consists of the join field, the remaining fields from file1 and then the remaining fields from file2. The default field separators are tab and space characters. In this case, multiple tabs and spaces count as a single field separator, and leading tabs and spaces are ignored. The default output field separator is a single space character. Many of the options use file and field numbers. Both file numbers and field numbers are 1 based, i.e., the first file on the command line is file number 1 and the first field is field number 1. The following options are available: -a file_number In addition to the default output, produce a line for each unpairable line in file file_number. -e string Replace empty output fields with string. -o list The -o option specifies the fields that will be output from each file for each line with matching join fields. Each element of list has the either the form 'file_number.field', where file_number is a file number and field is a field number, or the form '0' (zero), representing the join field. The elements of list must be either comma (',') or whitespace separated. (The latter requires quoting to protect it from the shell, or, a simpler approach is to use multiple -o options.) -t char Use character char as a field delimiter for both input and output. Every occurrence of char in a line is significant. -v file_number Do not display the default output, but display a line for each unpairable line in file file_number. The options -v 1 and -v 2 may be specified at the same time. -1 field Join on the field'th field of file 1. -2 field Join on the field'th field of file 2. When the default field delimiter characters are used, the files to be joined should be ordered in the collating sequence of sort(1), using the -b option, on the fields on which they are to be joined, otherwise join may not report all field matches. When the field delimiter char- acters are specified by the -t option, the collating sequence should be the same as sort(1) without the -b option. If one of the arguments file1 or file2 is ``-'', the standard input is used. EXIT STATUS
The join utility exits 0 on success, and >0 if an error occurs. COMPATIBILITY
For compatibility with historic versions of join, the following options are available: -a In addition to the default output, produce a line for each unpairable line in both file 1 and file 2. -j1 field Join on the field'th field of file 1. -j2 field Join on the field'th field of file 2. -j field Join on the field'th field of both file 1 and file 2. -o list ... Historical implementations of join permitted multiple arguments to the -o option. These arguments were of the form 'file_number.field_number' as described for the current -o option. This has obvious difficulties in the presence of files named '1.2'. These options are available only so historic shell scripts do not require modification. They should not be used in new code. LEGACY DESCRIPTION
The -e option causes a specified string to be substituted into empty fields, even if they are in the middle of a line. In legacy mode, the substitution only takes place at the end of a line. Only documented options are allowed. In legacy mode, some obsolete options are re-written into current options. For more information about legacy mode, see compat(5). SEE ALSO
awk(1), comm(1), paste(1), sort(1), uniq(1), compat(5) STANDARDS
The join command conforms to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
July 5, 2004 BSD
All times are GMT -4. The time now is 12:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy