AWK record length fix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK record length fix
# 1  
Old 10-08-2008
AWK record length fix

Hi Friends,

Need some help in AWK.

Working on AIX 5

Have been trying the following functionality to make the record length fixed:

Code:
if( length(record) < 300 )
   {
    printf("%-300s\n", record);
   }

In my opinion it will apply some fillers in the end.

Its is not making any changes to length (say input record length is 200 its coming out to be 200 and not 300)

Could any body please give some other option


Thanks in advance
Kanu
# 2  
Old 10-08-2008

I suspect that the method you are using the test the length is at fault, not awk. How are you doing it?

Try this:

Code:
if( length(record) < 300 )
   {
    printf("%-300s:\n", record);
   }

What result to you get now?
# 3  
Old 10-08-2008
thanks for the reply Johnson,

you piece of change is also not producing the desired o/p.Smilie

Any other suggestion is most welcome.


regards
Kanu
# 4  
Old 10-08-2008
It adds so many spaces until the number of characters per record is reached.
You should open your file with vi and set following option:

:set list

It will show the $ for the end of the lines is at position 300. How did you check it's not 300?

Tested with awk that comes with AIX 5.3.

Last edited by zaxxon; 10-08-2008 at 10:02 AM.. Reason: corrected a typo
# 5  
Old 10-08-2008
Quote:
Originally Posted by kanu_pathak
you piece of change is also not producing the desired o/p.Smilie

Any other suggestion is most welcome.

My only suggestion is to answer the questions I asked. It isn't possible to tell what's wrong if you don't provide enough information.

How are you capturing the output from awk?

How are you testing the length?

What result do you get after making the change I suggested?

Last edited by cfajohnson; 10-08-2008 at 09:37 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies

2. Shell Programming and Scripting

Convert comma separated file to fix length

Hi, I am converting a comma separated file to fixed field lenght and I am using that: COLUMNS="25 24 67 26 39 63 20 34 35 14 397" ( cat $indir/input_file.dat | \ $AWK -v columns="$COLUMNS" ' BEGIN { FS=","; OFS=""; split(columns, arr, " "); } { for(i=1; i<=NF;... (5 Replies)
Discussion started by: apenkov
5 Replies

3. Shell Programming and Scripting

Verifying Record Length

Hi all, We are going through a total migration from AIX-based server framework to Linux-based servers. When I am testing *.sh and *.awk in a lower environments, it abends at the same step everytime in verifying the record length of the first row of the source file. I know this source file... (11 Replies)
Discussion started by: SoloXX
11 Replies

4. Shell Programming and Scripting

Record length

Hi, The record length may be differ in afile. I want to display the records if the record length is not equal to 50 using sed/awk command. Thanks in Advance (6 Replies)
Discussion started by: NareshN
6 Replies

5. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. Shell Programming and Scripting

how to fix the column length in a file using Awk Prog

Hi I use the following code to read the file and to fix the length of the column of the record in the file 'Sample.txt' ls Samp* | awk ' { a=$1 } END{ FS="n" for(i=1;i<=NR;i++) { while( getline < a ) { f1=$0; print("Line::",f1); f2=substr(f1,1,10) print("Field1::",f2);... (10 Replies)
Discussion started by: meva
10 Replies

7. Shell Programming and Scripting

awk to find the length of each record.

Hi Guys, I wanted to print the length of each record and the record itself. I tried the following awk ... awk 'a=length(); {print $a,$0}' file1 But it is giving me the records instead of length. and also, it giving me each record twice. Means the value of a is not the length of the... (0 Replies)
Discussion started by: mac4rfree
0 Replies

8. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

9. Shell Programming and Scripting

Record Length too long -- AWK Problem

Hi All, I have a txt file which is an export of a query result from the database. The txt file contains 'Processid#sqlquery' from the database table.As the sqlquery is too long.... i am unable to get the fields seperated using the awk script as below:- cat sql.txt | awk -F'#' '{printf $2}'... (2 Replies)
Discussion started by: venkatajay_18
2 Replies

10. UNIX for Advanced & Expert Users

UNIX Default Record Length in AWK

Hello - QUESTION: Is there a way to override the default record length limitation over awk in Unix? Or, is there a better way to do what I am trying to do than the way I am trying to do it now? (See BACKGROUND and CURRENT PROCEDURE below...) BACKGROUND: In a Kornshell script, I have... (1 Reply)
Discussion started by: JLandry
1 Replies
Login or Register to Ask a Question