awk to find the length of each record.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to find the length of each record.
# 1  
Old 08-20-2009
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 ...

Code:
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 record but the record itself..

could you please point out my mistake..

thanks
Magesh

---------- Post updated at 06:52 PM ---------- Previous update was at 06:46 PM ----------

Guys, i found the answer..

Code:
awk '{print  length($0),$0}' file1

Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Find the replicate record using awk

We usually use the following awk code to delete of find out the replicate record. awk -F, '{a++} END {for (i in a) if (a>=2) print i a}' file My question is how can I print the whole record. The following code doesn't work. awk -F, '{a++} END {for (i in a) if (a>=2) print $0}' file ... (8 Replies)
Discussion started by: xshang
8 Replies

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

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: if( length(record) < 300 ) { printf("%-300s\n", record); } In my opinion it will apply some fillers in the end. Its is not making any... (4 Replies)
Discussion started by: kanu_pathak
4 Replies

7. Shell Programming and Scripting

Awk:Find length of string omitting quotes

Hi , I have a file named "sample" having the data as follows. "663005487","USD",0,1,"NR" If i give like a=`awk -F ',' '{printf length($2)}' sample` (Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5. How to do this..... (2 Replies)
Discussion started by: jayakumarrt
2 Replies

8. 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

9. 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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)