Sponsored Content
Top Forums Shell Programming and Scripting Help with finding length of a field Post 302151035 by Klashxx on Thursday 13th of December 2007 12:10:20 PM
Old 12-13-2007
One of the ways:
Code:
echo "2|251|25G|NY|NY"|awk '{printf("%0.5d|%0.5d|",$1,$2);print $3,$4,$5}' FS='|' OFS='|'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding out the length of a string held within a variable

:confused: Does anyone know which command I can use to find out the length of a string held within a variable? (5 Replies)
Discussion started by: dbrundrett
5 Replies

2. UNIX for Dummies Questions & Answers

Validating fixed length field...

What's wrong with this part of my script? I just want to put each column from a fixed length file into a variable so I can validate each field later in the script. exec< myfile.dat while read afile; do a=`echo $(echo $afile |cut -c1-10)` echo "$a" b=`echo $(echo $afile |cut -c11-20)`... (12 Replies)
Discussion started by: giannicello
12 Replies

3. Shell Programming and Scripting

Finding the length of a string in a field

I have a field MPN-BANK-NUMBERO:006,00:N in a file FILE1 How can i display the length of the Bank Number.Any idea ? The output shud take the following format FILE 1 6 Where 1 is the starting position and 6 is the Ending position. (9 Replies)
Discussion started by: bobby1015
9 Replies

4. Shell Programming and Scripting

Finding the records with a specified length

I have a sample txt file which has different variable lengths of 2,10,3,15. What is the command that I need use in order to get the record count that has length '3' Thanks (3 Replies)
Discussion started by: bobby1015
3 Replies

5. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

6. Shell Programming and Scripting

Search for a particular field length and append '0' if less less than 10

Hi, I am new to Unix. Please help me in finding solution for the below scenario. I have a flat file that contains data like 378633410|3013505414|new_378633410|ALBERT|WALLS|378633410|Rew||||||| 351049045|239|new_351049045|JIM|COOK|351049045|Rew|||||||... (6 Replies)
Discussion started by: anandek
6 Replies

7. Shell Programming and Scripting

Finding the length of the longest column

Hi, I am trying to figure out how to get the length of the longest column in the entire file (because the length varies from one row to the other) I was doing this at first to check how many fields I have for the first row: awk '{print NF; exit}' file Now, I can do this: awk '{ if... (4 Replies)
Discussion started by: MIA651
4 Replies

8. Shell Programming and Scripting

Replace a field with a character as per the field length

Hi all, I have a requirement to replace a field with a character as per the length of the field. Suppose i have a file where second field is of 20 character length. I want to replace second field with 20 stars (*). like ******************** As the field is not a fixed one, i want to do the... (2 Replies)
Discussion started by: gani_85
2 Replies

9. Shell Programming and Scripting

How to change variable length field?

Hello, I have a file with a date field with various lengths. For example: m/d/yyyy hh:mm or h:mm mm/dd/yyyy hh:mm or h:mm Is there a way using sed or awk to change the field to m/d/y ? I don't need the hours and minutes in that field, just the date in the proper format. Thanks in... (6 Replies)
Discussion started by: sonnyo916
6 Replies

10. Shell Programming and Scripting

Finding difference between two columns of unequal length

Hi, I have two files which look like this cat waitstate.txt 18.2 82.1 cat gostate.txt 5.6 5.8 6.1 6.3 6.6 6.9 7.2 7.5 (4 Replies)
Discussion started by: jamie_123
4 Replies
AR(5)							      BSD File Formats Manual							     AR(5)

NAME
ar -- archive (library) file format SYNOPSIS
#include <ar.h> DESCRIPTION
The archive command ar combines several files into one. Archives are mainly used as libraries of object files intended to be loaded using the link-editor ld(1). A file created with ar begins with the ``magic'' string "!<arch> ". The rest of the archive is made up of objects, each of which is com- posed of a header for a file, a possible file name, and the file contents. The header is portable between machine architectures, and, if the file contents are printable, the archive is itself printable. The header is made up of six variable length ASCII fields, followed by a two character trailer. The fields are the object name (16 charac- ters), the file last modification time (12 characters), the user and group id's (each 6 characters), the file mode (8 characters) and the file size (10 characters). All numeric fields are in decimal, except for the file mode which is in octal. The modification time is the file st_mtime field, i.e., CUT seconds since the epoch. The user and group id's are the file st_uid and st_gid fields. The file mode is the file st_mode field. The file size is the file st_size field. The two-byte trailer is the string "` ". Only the name field has any provision for overflow. If any file name is more than 16 characters in length or contains an embedded space, the string "#1/" followed by the ASCII length of the name is written in the name field. The file size (stored in the archive header) is incre- mented by the length of the name. The name is then written immediately following the archive header. Any unused characters in any of these fields are written as space characters. If any fields are their particular maximum number of charac- ters in length, there will be no separation between the fields. Objects in the archive are always an even number of bytes long; files which are an odd number of bytes long are padded with a newline (`` '') character, although the size in the header does not reflect this. SEE ALSO
ar(1), stat(2) HISTORY
There have been at least four ar formats. The first was denoted by the leading ``magic'' number 0177555 (stored as type int). These ar- chives were almost certainly created on a 16-bit machine, and contain headers made up of five fields. The fields are the object name (8 characters), the file last modification time (type long), the user id (type char), the file mode (type char) and the file size (type unsigned int). Files were padded to an even number of bytes. The second was denoted by the leading ``magic'' number 0177545 (stored as type int). These archives may have been created on either 16 or 32-bit machines, and contain headers made up of six fields. The fields are the object name (14 characters), the file last modification time (type long), the user and group id's (each type char), the file mode (type int) and the file size (type long). Files were padded to an even number of bytes. For more information on converting from this format see arcv(8). The current archive format (without support for long character names and names with embedded spaces) was introduced in 4.0BSD. The headers were the same as the current format, with the exception that names longer than 16 characters were truncated, and names with embedded spaces (and often trailing spaces) were not supported. It has been extended for these reasons, as described above. This format first appeared in 4.4BSD. COMPATIBILITY
No archive format is currently specified by any standard. AT&T System V UNIX has historically distributed archives in a different format from all of the above. BSD
June 9, 1993 BSD
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy