Sponsored Content
Top Forums Shell Programming and Scripting Extracting fixed length number from a text file Post 302994213 by vgersh99 on Monday 20th of March 2017 12:33:24 PM
Old 03-20-2017
Quote:
Originally Posted by dsid
@vgersh. awk -F ' ' is for defining delimiters as far as I know, what does your command mean
Code:
awk -F'[][]'

. The next part is the start of the string I got that and I think $NF would be number of fields, but why are you subtracting 1 from it and then printing that out.
-F defines field delimiters. In this particular case the field delimiters are [] as the 23-digit long string is surrounded by [].
We subtract 1 from $NF because the LAST field is following the ]. The field next to last is your 23-digit long string.
This User Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

convert XML file into Text file(fixed length)

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> ... (0 Replies)
Discussion started by: ram2s2001
0 Replies

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

4. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

5. Shell Programming and Scripting

fixed length text file padding issues in AIX

Hi, I have a fixed length text file that needs to be cut into individual files in aix and facing padding issues. If I have multiple blank spaces in the file it is just making it one while cutting the files.. Eg:- $ - blank space filename:file.txt ... (2 Replies)
Discussion started by: techmoris
2 Replies

6. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

7. Shell Programming and Scripting

Help with extracting words from fixed length files

I am very new to scripting and need to write a script that will extract the account number from a line that begins with HDR. For example, the file is as follows HDR2010072600300405505100726 00300405505 LBJ FREEWAY DALLAS TELEGRAPH ... (9 Replies)
Discussion started by: bds052189
9 Replies

8. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

9. UNIX for Dummies Questions & Answers

Fixed length file extracting values in columns

How do I extract values in a few columns in a row of a fixed length file? If there are 8 columns and I need to extract values of 2nd,4th and 6 th columns, how do i do that? I used cut command, this I used only for one column. How do I do it more than one column? The below command will give... (1 Reply)
Discussion started by: princetd001
1 Replies

10. UNIX for Dummies Questions & Answers

Length of a fixed width file

I have a fixed width file of length 53. when is try to get the lengh of the record of that file i get 2 different answers. awk '{print length;exit}' <File_name> The above code gives me length 50. wc -L <File_name> The above code gives me length 53. Please clarify on... (2 Replies)
Discussion started by: Amrutha24
2 Replies
magic(4)						     Kernel Interfaces Manual							  magic(4)

NAME
magic - Magic file for the file command SYNOPSIS
/etc/magic DESCRIPTION
The magic file is used by the file command to identify files that have some sort of magic number. A magic number is any numeric or string constant that identifies the file containing the constant. The format for the magic file is as follows: offset type operator,value string The fields should be separated by tabs. Each record must be contained on one line. The fields contain the following data: This field contains the number of bytes from the beginning of the file on which you are running the file command to the first byte of the magic number of character string you want to identify. Use a right angle bracket (>) to indicate a continuation line that supplies additional information describing the file. This field contains information about the data type of the magic number or character string at the specified byte offset. Valid data types for this field are: Unsigned character type Unsigned short type Long type Character (byte) string This field contains instructions for the file command on how to compare the value read from the file being checked with the value stored in the Value Type field of the magic file. The valid comparison operators are: The two values are equal. The value in the file being checked is greater than the value in the magic file. The value in the file being checked is less than the value in the magic file. All the bits in the magic file value must be set in the value from the file being checked. Note that the Comparison Operator field is optional. If you do not specify the operator, the values are expected to be equal. This field contains the value used to compare what is read from the file being checked by the file command. You can use decimal, hex, or octal numbers in this field or character strings in the form of regular expressions. Precede all hex numbers with the characters zero and x (for example, 0x80). To specify an octal number, precede it with a zero (for example, 0200). Decimal numbers require no special representation and should be written as integers (for example, 128). The rules for specifying character strings follow those of the ed editor (see ed(1)) for regular expressions, with two extensions: You use the backslash () to escape an unprintable character. The string can contain all special character such as , , , and f. If a backslash appears in the string, it must be escaped with a second backslash (\). You can use octal representation to specify any byte value other than zero (0). Text found in the file can be inserted into the printed string if it is preceded and followed by \% delimiters. All text found between these delimiters is displayed as the print string. This regular expression search never terminates until a match is explicitly found or rejected. The special character is a valid character in the patterns. Therefore, the pattern .* should never be used here. This field contains the string to print. The string provides information about the file. The string can include text found in the file when requested with an appropriate printf() format. EXAMPLES
The following is an example of a script: string ^#!{ }*\%[^ ]*\% %s The following are examples of executable images: >2 short 02 POSIX >2 short 01 SVID >16 long >0 not stripped The following are examples of text and data files: 0 string ^1h[0-9][0-9][0-9][0-9][0-9] sccsfile 0 string ^#ifndef c program 0 string ^070707 ASCII cpio archive FILES
/etc/magic RELATED INFORMATION
Commands: file(1) delim off magic(4)
All times are GMT -4. The time now is 12:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy