using awk make an field as 5 digit and display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk make an field as 5 digit and display
# 1  
Old 09-11-2008
using awk make an field as 5 digit and display

using awk convert 3 rd fileld of file as 5 digit and then display changed file.
like
1 2
23445 3452 3343
3 5 6 6
================
o/p:-
1 2
23445 3452 03343
3 5 00006 6
# 2  
Old 09-11-2008
Use sprintf to format the field:

Code:
awk 'NF>2{$3=sprintf("%05d",$3)}1' file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add tab after digit in specific field in file

I am trying to add a tab after the last digit in $3 in the input. The grep below is all I can think off. Thank you :) sed -n 's/:/&/p' input input chr1 955542 955763AGRN-6|gc=75 chr1 957570 957852AGRN-7|gc=61.2 chr1 976034 976270AGRN-9|gc=74.5 desired output chr1... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

3. Shell Programming and Scripting

Problem with awk double digit fields

Hello Everyone, This 10th field is giving too much problem in AWK. How do i overcome ? pls suggest Thanks! cat /tmp/data_rank| awk 'BEGIN{ print "HT No" "," "Name" "," "Maths" "," "Physics" "," "Chemistry" "," "Total" "," "Gender" "," "University" "," "RANK Global" "," "Rank... (2 Replies)
Discussion started by: InduInduIndu
2 Replies

4. Shell Programming and Scripting

Adding Zeros to make it 8 digit

Dear Buddies, My query may be pretty simple but I am stuck because of it. Please give me a solution. Query is I have a variable (say $A) which can have any number starting from 1 digit to 8 digit i.e. any number from 1 to 99999999. Now, I want output as 8 digit even if variable has only 1 digit.... (3 Replies)
Discussion started by: anushree.a
3 Replies

5. Shell Programming and Scripting

awk Loop 4 digit fields

Can somebody help me on this script with a loop? gawk --re-interval '{if(($1 ~ /]{4}/) && ($2 ~ /]{4}/) && ($3 ~ /]{4}/)) print $0}' I would like to loop until NF and while $i does not match ($i ~ /]{4}/) anymore then print all matching $i and exit. (5 Replies)
Discussion started by: sdf
5 Replies

6. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

7. Shell Programming and Scripting

Awk numeric range match only one digit?

Hello, I have a text file with lines that look like this: 1974 12 27 -0.72743 -1.0169 2 1.25029 1974 12 28 -0.4958 -0.72926 2 0.881839 1974 12 29 -0.26331 -0.53426 2 0.595623 1974 12 30 7.71432E-02 -0.71887 3 0.723001 1974 12 31 0.187789 -1.07114 3 1.08748 1975 1 1 0.349933 -1.02217... (2 Replies)
Discussion started by: meridionaljet
2 Replies

8. Shell Programming and Scripting

expr Field 1 + Field 2 Since when does 2 positives make a negative

Please help. I am adding 2 fields which are both positive and the result is negative. What am I missing? FileEHash=`expr ${Field1} + ${Field2}` >/dev/null Debug Results + expr 02100002 + 2009701914 EntryHash=2011801916 + expr 02100002 + 2146202044 FileEHash=-2146665250 How do... (2 Replies)
Discussion started by: ski
2 Replies

9. UNIX for Dummies Questions & Answers

Awk help needed for display particular field alone for searching pattern

Hi, I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for, Note: The searching field varies its position... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

10. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies
Login or Register to Ask a Question