Format width of a single column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format width of a single column
# 1  
Old 07-08-2014
Format width of a single column

I have a tab delimited table with more than 126 columns. One of the columns however contains more than 90 characters and this makes the table really difficult to read. I know I can use awk and printf to format the width but then I'll need to write, $1, $2, $3, ...:

awk '{OFS = FS = "\t"} { printf "%-88s %s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n", $1,$2,$3,$4,$5,$6,$7,$8}'

I don't think this is the right way to do it. Is there a method where I can just simply format the width of one particular column?

Thank you.
# 2  
Old 07-08-2014
How about this as an example:

Code:
$ cat infile
1,  103.3,8,Arlen Specter  ,0
2,   84.1,6,John McCain    ,0
3,   22.5,6,Arnold Schwarzenegger,0
4,    7.0,4,Dick Drubin    ,0

$ cat fix4
awk 'BEGIN{FS=OFS=","} {$4=sprintf("%-22s",$4); print}' infile

$ ./fix4
1,  103.3,8,Arlen Specter         ,0
2,   84.1,6,John McCain           ,0
3,   22.5,6,Arnold Schwarzenegger ,0
4,    7.0,4,Dick Drubin           ,0

# 3  
Old 07-09-2014
Thanks for the help. sprintf, should spend a bit of time learning this.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Htop process viewer - set column width

I try to enlarge the htop column's width. I've found a solution, but it seems very specific and also too difficult. Is there any simpler way to make all the characters in a column visible? (0 Replies)
Discussion started by: plaidshirtuser
0 Replies

2. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

3. Shell Programming and Scripting

To replace the value of the column in a fixed width file

I have a fixed with file with header & trailer length having the same length of the detail record file. The details record length of this file is 24, for Header and Trailer the records will be padded with spaces to match the record length of the file Currently I am adding 3 spaces in header... (14 Replies)
Discussion started by: ginrkf
14 Replies

4. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

5. UNIX for Dummies Questions & Answers

Remove duplicates based on a column in fixed width file

Hi, How to output the duplicate record to another file. We say the record is duplicate based on a column whose position is from 2 and its length is 11 characters. The file is a fixed width file. ex of Record: DTYU12333567opert tjhi kkklTRG9012 The data in bold is the key on which... (1 Reply)
Discussion started by: Qwerty123
1 Replies

6. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

7. Shell Programming and Scripting

awk: creating a fixed-width single file from 2 different files

I have to create a single file from three files, Please see below for samples: day.txt 20090101 20090102 item.txt 123456789101 12345678910209 1234567891 str.txt 1 12 123 output.txt 20090101123456789101 1 0 2009010112345678910209 12 ... (2 Replies)
Discussion started by: tamahomekarasu
2 Replies

8. UNIX for Dummies Questions & Answers

top's USER column width variation

hello, does anyone know how to expand the column width so it could contain full USER cell and not cut it in top ? Now it has eleven symbols but I can see only eight actualy I found only PID, PPID and %CPU columns variation possibilities in changelog (procps v.3.2.5). thanks in advance. (1 Reply)
Discussion started by: bugs_moran
1 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies
Login or Register to Ask a Question