Awk print all columns in delimited file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk print all columns in delimited file
# 1  
Old 08-24-2012
Awk print all columns in delimited file

text file example
1,222222222222,333,444444444444444
111111111,22,33333333,444


desired output
Code:
1                            222222222222 333       444444444444444
111111111                    22           33333333 444

I have a delimeted file which I want to print in a table like format. The command below is close however tab is not always big enough to properly space the columns?
Code:
awk  'BEGIN { FS=";"; OFS=" "} { $1=$1;print $0 }' deals_RBS.log

Any suggestions?

Thansk

Last edited by Franklin52; 08-24-2012 at 08:34 AM.. Reason: Adding code tags
# 2  
Old 08-24-2012
I can't test it but this should work :

Code:
column -s ',' -t deals_RBS.log


Last edited by delugeag; 08-24-2012 at 10:17 AM..
# 3  
Old 08-24-2012
Try
Code:
awk -F, '{for (i=1;i<=NF;i++) printf "%-15s",$i; print ""}'

and adjust the field length (15) according to your needs.
# 4  
Old 08-24-2012
Hi RudiC, that kind of works, but not really. Some columns are very short fileds i.e 1 or 2 chars, and some column are 20-25 chars wide.

If I increase -15 -> -30, the file goes over multiple lines and is unreadable.
Howerver if I keep it at -15, some columns are not seperated by anything.

Really what I need is to loop through each column of data and find the maximum width. I thought about cuting each colum and then pasting back together?
# 5  
Old 08-24-2012
delugeag's "column" proposal does exactly what you require. I was aiming for columns of equal, constant width, and his proposal adapts to the respective neccessary width.
# 6  
Old 08-24-2012
Quote:
Originally Posted by RudiC
delugeag's "column" proposal does exactly what you require. I was aiming for columns of equal, constant width, and his proposal adapts to the respective neccessary width.
Hi Rudic,

I tried with delugeag's solution... getting below error and one line missing in output..

Code:
$ column -s ',' -t file2
column: line too long
1          222222222222  333       444444444444444
111111111  22            33333333  444
143        222222222222  33433     44444444444444434
12434      222222222222  333       444
14324      2222222222    3433      4444444

$ cat file2
1,222222222222,333,444444444444444
111111111,22,33333333,444
143,222222222222,33433,44444444444444434
12434,222222222222,333,444
14324,2222222222,3433,4444444
143,222222222,334333,44444444444

What could be the reason for this...?
# 7  
Old 08-24-2012
Your file2 as posted works fine for me, even when I make lines four times as long. Sure you got no special chars in the original (not posted) file?


Got it: missing <newline> at the end of last line!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify comma delimited file columns.

Please help me to update a file which contains date values as below:- From:- "1912108",20161130,"2016-12-01-00.00.00.000000","2016-12-01-08.37.12.000000" "1912108",20161201,"2016-12-02-00.00.00.000000","2016-12-02-08.28.22.000000" To:- "1912108",2016-11-30,"2016-12-01... (7 Replies)
Discussion started by: KrishnaVM
7 Replies

2. Shell Programming and Scripting

[Solved] awk compare two different columns of two files and print all from both file

Hi, I want to compare two columns from file1 with another two column of file2 and print matched and unmatched column like this File1 1 rs1 abc 3 rs4 xyz 1 rs3 stu File2 1 kkk rs1 AA 10 1 aaa rs2 DD 20 1 ccc ... (2 Replies)
Discussion started by: justinjj
2 Replies

3. Shell Programming and Scripting

Remove few columns from pipe delimited file

I have file as below column1|column2|column3|column4|column5| fill1|fill2|fill3|fill4|fill5| abc1|abc2|abc3|abc4|abc5| . . . . i need to remove column2,3, from that file column1|column4|column5| fill1|fill4|fill5| abc1|abc4|abc5| . . . (3 Replies)
Discussion started by: greenworld123
3 Replies

4. Shell Programming and Scripting

awk read one delimited file, search another delimited file

Hello folks, I have another doozy. I have two files. The first file has four fields in it. These four fields map to different locations in my second file. What I want to do is read the master file (file 2 - 23 fields) and compare each line against each record in file 1. If I get a match in all four... (4 Replies)
Discussion started by: dagamier
4 Replies

5. Shell Programming and Scripting

awk compare specific columns from 2 files, print new file

Hello. I have two files. FILE1 was extracted from FILE2 and modified thanks to help from this post. Now I need to replace the extracted, modified lines into the original file (FILE2) to produce the FILE3. FILE1 1466 55.27433 14.72050 -2.52E+03 3.00E-01 1.05E+04 2.57E+04 1467 55.27433... (1 Reply)
Discussion started by: jm4smtddd
1 Replies

6. Shell Programming and Scripting

grep/awk to only print lines with two columns in a file

Hey, Need some help for command to print only lines with two columns in a file abc 111 cde 222 fgh ijk 2 klm 12 23 nop want the ouput to be abc 111 cde 222 ijk 2 Thanks a lot in advance!!! (3 Replies)
Discussion started by: leo.maveriick
3 Replies

7. Shell Programming and Scripting

Read columns from delimited file in UNIX

Hello I need to read the columns from a flat file delimited by Hex code X02. The Sample file is Red^B1000^BJohn Blue^B2000^BSam Green^B3000^BDan Note: Hex code X02 shows as ^B in vi. I need to read the file and process the columns in each row. I tried using awk -F command but... (7 Replies)
Discussion started by: injey
7 Replies

8. Shell Programming and Scripting

using awk to print some columns of a file

Hi, i have a file with content 00:01:20.613 'integer32' 459254 00:01:34.158 459556 00:01:36.626 'integer32' 459255 and i want to print only output as below 00:01:20.613 459254 00:01:34.158 459556 00:01:36.626 459255 i dont want the word 'integer32' which is the second column. i... (2 Replies)
Discussion started by: dealerso
2 Replies

9. UNIX for Dummies Questions & Answers

nth Columns in a Tab delimited file

Hi Can anyone help me to identify the nth field from a Tab delimited file? Thanks Subrat (8 Replies)
Discussion started by: subrat
8 Replies

10. Shell Programming and Scripting

Reading columns in tab delimited file

I want to read only one column in "|" delimited file and write that column to a new file. For Ex: Input File 1|abc|324|tt 2|efd|11|cbcb 3||1|fg 4|ert|23|88 Output : I want to read column 3 in diff file. 324 11 1 88 Can anyone give me inputs on this ? (2 Replies)
Discussion started by: net
2 Replies
Login or Register to Ask a Question