Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Printf awk: argument to adjust automatically width to the largest value Post 302605908 by itkamaraj on Friday 9th of March 2012 02:54:32 AM
Old 03-09-2012
Code:
nawk -F"\t" 'BEGIN{b=0}{for(i=1;i<=NF;i++){a=length($i);if(a>b)b=a;}}END{print b}' input.txt

the above awk will give the longest field in your file.

after that you can pass that value to awk and pass it to the printf
This User Gave Thanks to itkamaraj For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

fixed-width printf() output on an XmList on Solaris

This one is a bit of bugger and I'm not sure if it's entirely relevant to this board but here goes... I'm trying to produce some fixed width output to a List widget (X11/Motif GUI) So, I use something similar to: sprintf(Buffer, "%*d%*f", 20, some_integer, 20, some_float); This gives me a... (0 Replies)
Discussion started by: trido
0 Replies

2. UNIX for Dummies Questions & Answers

Fixed Width file using AWK

I am using the following command at the Unix prompt to make my 'infile' into a fixed width file of 100 characters. awk '{printf "%-100s\n",$0}' infile > outfile However, there are some records with a special character "©" These records are using 3 characters in place of one and my record... (2 Replies)
Discussion started by: alok.benjwal
2 Replies

3. Shell Programming and Scripting

largest field , awk , help

Hi All, My file is like this: $ cat max.txt abcd:1982:a efghij:1980:e klmn:1923:k opqrst:1982:o I have to find out the largest first field and the corresponding line. i.e Output required: efghij efghij:1980:e opqrst opqrst:1982:o HTH, jkl_jkl (6 Replies)
Discussion started by: jkl_jkl
6 Replies

4. Shell Programming and Scripting

AWK (how) to get smallest/largest nr of ls -la

Hey, This is a long-shot however, I am stuck with the following problem: I have the output from ls -la, and I want to sort some of that data out by using AWK to filter it. ls -la | awk -f scriptname.awk Input: For example: drwxr-xr-x 3 user users 4096 2010-03-14 20:15 bin/... (5 Replies)
Discussion started by: abciscool
5 Replies

5. Shell Programming and Scripting

awk second largest, third largest value

I have two text files like this: file1.txt: 133 10 133 22 133 13 133 56 133 78 133 98 file2.txt: 158 38 158 67 158 94 158 17 158 23 I'm basically trying to have awk check the second largest value of the second column of each text file, and cat it to its own text file. There... (13 Replies)
Discussion started by: theawknewbie
13 Replies

6. Shell Programming and Scripting

Using printf (or other?) to create variable fixed width text

I would like to use printf (or something else?) to create a line of text that has varying column widths. This will be used to create a fixed width file (with varying column widths). For example, consider variables $1 $2 $3 are equal to a, b, c respectively and they should be printed in column... (10 Replies)
Discussion started by: farrenthorpe
10 Replies

7. Shell Programming and Scripting

awk to combine matches and use a field to adjust coordinates in other fields

Trying to output a result that uses the data from file to combine and subtract specific lines. If $4 matches in each line then the last $6 value is added to $2 and that becomes the new$3. Each matching line in combined into one with $1 then the original $2 then the new$3 then $5. For the cases... (4 Replies)
Discussion started by: cmccabe
4 Replies

8. Shell Programming and Scripting

awk to combine all matching fields in input but only print line with largest value in specific field

In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited, that are in $1 of gene which is just a single column of text. However only the line with the greatest $9 value in input needs to be printed. So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies

9. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

awk to adjust text and count based on value in field

The below awk executes as is and produces the current output. It isvery close but what Ican not seem to do is add the -exon..., the ... portion comes from $1 and the _exon is static and will never change. If there is + sign in $4 then the ... is in acending order or sequential. If there is a - in... (2 Replies)
Discussion started by: cmccabe
2 Replies
ucblinks(1B)					     SunOS/BSD Compatibility Package Commands					      ucblinks(1B)

NAME
ucblinks - adds /dev entries to give SunOS 4.x compatible names to SunOS 5.x devices SYNOPSIS
/usr/ucb/ucblinks [-e rulebase] [-r rootdir] DESCRIPTION
ucblinks creates symbolic links under the /dev directory for devices whose SunOS 5.x names differ from their SunOS 4.x names. Where possi- ble, these symbolic links point to the device's SunOS 5.x name rather than to the actual /devices entry. ucblinks does not remove unneeded compatibility links; these must be removed by hand. ucblinks should be called each time the system is reconfiguration-booted, after any new SunOS 5.x links that are needed have been created, since the reconfiguration may have resulted in more compatibility names being needed. In releases prior to SunOS 5.4, ucblinks used a nawk rule-base to construct the SunOS 4.x compatible names. ucblinks no longer uses nawk for the default operation, although nawk rule-bases can still be specifed with the -e option. The nawk rule-base equivalent to the SunOS 5.4 default operation can be found in /usr/ucblib/ucblinks.awk. OPTIONS
-e rulebase Specify rulebase as the file containing nawk(1) pattern-action statements. -r rootdir Specify rootdir as the directory under which dev and devices will be found, rather than the standard root directory /. FILES
/usr/ucblib/ucblinks.awk sample rule-base for compatibility links ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
devlinks(1M), disks(1M), ports(1M), tapes(1M), attributes(5) SunOS 5.10 13 Apr 1994 ucblinks(1B)
All times are GMT -4. The time now is 11:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy