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
audit(2)							   System Calls 							  audit(2)

NAME
audit - write a record to the audit log SYNOPSIS
cc [ flag ... ] file ... -lbsm -lsocket -lnsl [ library... ] #include <sys/param.h> #include <bsm/libbsm.h> int audit(caddr_t record, int length); DESCRIPTION
The audit() function queues a record for writing to the system audit log. The data pointed to by record is queued for the log after a mini- mal consistency check, with the length parameter specifying the size of the record in bytes. The data should be a well-formed audit record as described by audit.log(4). The kernel validates the record header token type and length, and sets the time stamp value before writing the record to the audit log. The kernel does not do any preselection for user-level generated events. If the audit policy is set to include sequence or trailer tokens, the kernel will append them to the record. RETURN VALUES
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The audit() function will fail if: E2BIG The record length is greater than the maximum allowed record length. EFAULT The record argument points outside the process's allocated address space. EINVAL The header token in the record is invalid. ENOTSUP Solaris Audit is not defined for this system. EPERM The {PRIV_PROC_AUDIT} privilege is not asserted in the effective set of the calling process. USAGE
Only privileged processes can successfully execute this call. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
bsmconv(1M), audit(1M), auditd(1M), svcadm(1M), auditon(2), getaudit(2), audit.log(4), attributes(5), privileges(5) NOTES
The functionality described in this man page is available only if the Solaris Auditing has been enabled and the audit daemon auditd(1M) has not been disabled by audit(1M) or svcadm(1M). See bsmconv(1M) for more information. SunOS 5.11 16 Apr 2008 audit(2)