text in columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting text in columns
# 1  
Old 01-09-2009
[solved]text in columns

Hi, I'm reading from a file some values (in bash) and I would like to display in screen like that:
Code:
1         This is an example                    324.23MB                   XVID 
2         This is other better example          182.21MB                   Peliculas
 ............. .............

I do: awk '{print $1"\t"$2.... But the text isn't aligned. Could you help me ? Many thanks!!!

Last edited by mierdatuti; 01-10-2009 at 08:38 AM..
# 2  
Old 01-09-2009
Try it with printf, something like:

Code:
printf "%-10s%-50s%-75s%-10s" $1 $2 $3 $4

Regards
# 3  
Old 01-09-2009
Quote:
Originally Posted by Franklin52
Try it with printf, something like:

Code:
printf "%-10s%-50s%-75s%-10s" $1 $2 $3 $4

Regards
Thanks!
But it doesn't works me:

Code:
awk: run time error: not enough arguments passed to printf("%-10s%-50s%-75s%-10s%1PlayBoy Cyber Club - Playmate Xtra HD Clips WEB-DL 720p H264 AAC-CtrlHDHD-Adulto (+18)6.58 GB")
        FILENAME="-" FNR=1 NR=1
awk: run time error: not enough arguments passed to printf("%-10s%-50s%-75s%-10s%2Lupin.3.El.Castillo.de.Cagliostro.720.bluray[HDCity.es][PS3Team].m2tsHD-PS34.30 GB")
        FILENAME="-" FNR=1 NR=1
awk: run time error: not enough arguments passed to printf("%-10s%-50s%-75s%-10s%3Los hombres de Paco 7x01 [DVBRip] [DIVX]Series699.44 MB")

I try:

echo $Line | awk 'BEGIN {FS="#"} {printf "%-10s%-50s%-75s%-10s%" $1 $2 $3 $4}'

Last edited by mierdatuti; 01-09-2009 at 04:21 PM..
# 4  
Old 01-09-2009
The given command was the bash syntax. With awk you have to separate the arguments with a comma:

Code:
printf("%-10s%-50s%-75s%-10s", $1, $2, $3, $4)

or:

Code:
printf "%-10s%-50s%-75s%-10s", $1, $2, $3, $4

Regards
# 5  
Old 01-10-2009
Quote:
Originally Posted by Franklin52
The given command was the bash syntax. With awk you have to separate the arguments with a comma:

Code:
printf("%-10s%-50s%-75s%-10s", $1, $2, $3, $4)

or:

Code:
printf "%-10s%-50s%-75s%-10s", $1, $2, $3, $4

Regards

Many thanks ... it works!
Thank you very much
SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert text to columns

Hi. I need an input file of a single word pr. line converted in into a list of random pairs. i need input like this word1 word2 word3 word4 to be outputted like this: word3 word1 word2 word4 My attempt is a tedious while loop like this: nfiles=$(cat inputfile | wc -l) ... (4 Replies)
Discussion started by: BotHead
4 Replies

2. Shell Programming and Scripting

Replace text in columns

I have two files in below formats: cat file1 abc|abcd|10|1020 10|xyz|1010|1020 abc|abcd|10|1020 10|xyz|1010|1020 cat file2 abc|abcd|10|1020 11|xyz|1010|1020 abc|abcd|12|1020 10|xyz|1011|1020 abc|abcd|11|1020 10|xyz|1010|1020 abc|abcd|10|1020 10|xyz|1010|1020 I am generating a... (3 Replies)
Discussion started by: ctrld
3 Replies

3. Shell Programming and Scripting

Text columns processing using awk

P { margin-bottom: 0.25cm; line-height: 120%; }CODE.cjk { font-family: "WenQuanYi Micro Hei",monospace; }CODE.ctl { font-family: "Lohit Hindi",monospace; }A:link { } I'm trying to build an awk statement to print from a file (file1): A 1,2,3 * A 4,5,6 ** B 1 ... (4 Replies)
Discussion started by: dovah
4 Replies

4. Programming

Read columns from text files

Dear All, I have basic structure of the C++ code . It suppose to read particular columns from some txt file. The txt file look like following (snippet). I have to ask the details for instance 'id' information for rows satisfying text with red color. The issue is that the txt file has not just the... (2 Replies)
Discussion started by: emily
2 Replies

5. Shell Programming and Scripting

How to concatenate 2-columns by 2 -columns for a text file?

Hello, I want to concatenate 2-columns by 2-columns separated by colon. How can I do so? For example, I have a text file containing 6 columns separated by tab. I want to concatenate column 1 and 2; column 3 and 4; column 5 and 6, respectively, and put a colon in between. input file: 1 0 0 1... (10 Replies)
Discussion started by: huiyee1
10 Replies

6. Shell Programming and Scripting

Transpose few columns alone in a Text file

Hi Friends, I am Stuck up with a problem on transposing Rows to Coloumns.. Though there are many threads on this my problem is little difficult.. I have a tab separated file like Below, computer selling_loc currency_type manufacturer_name salesweek-wk1 sales-wk2 ...wk-3 ..wk4 till... (7 Replies)
Discussion started by: heinz_holan
7 Replies

7. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

Can I use columns from text files in if statements?

Currently I am stuck on my program for my if statement, as I do not no how to get a specific collumn of text to check against my variable. df -k /home/* > fd.txt cat df.txt | tr -s " " | awk '{print $3, $4, $1}' > dfcap.txt echo -n "Enter the size (in kilobytes) you wish to check against... (18 Replies)
Discussion started by: ninjafish
18 Replies

9. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 Replies

10. UNIX for Dummies Questions & Answers

Text formatting to 132 columns

I want to take a file that is generated in 132 columns from a unix based report generator and transfer it to a windows environment and preserve the column length. Any ideas how I can do this so that whatever windows based text editor that reads the document will know it should be in 132 columns?... (16 Replies)
Discussion started by: jmossman
16 Replies
Login or Register to Ask a Question