Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Finding a column in a flatfile Post 12807 by peter.herlihy on Monday 7th of January 2002 05:02:22 PM
Old 01-07-2002
Finding a column in a flatfile

I have a file which is fixed width columns. This is an offset buffer - rather than space or tab delimited. There are upto about 8 columns and I need to get all of the column 5's values into another file.

The problem is that because the delimiter is a space - and some fields are blank - the 5th field is sometimes taken as the 6th - so I lose quite a bit of data.

I want to find a way to output just the values from the 50th - 60th positions on the line into another file - for all lines in a large text file.

Ideally I'd like to get two columns for each line.....but I imagine that should be easy enough if I can figure out how to get the column I want.

I tried " awk -F" " '{print $5 "," $1 }' " - but this gives me the problem...any ideas?Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding the most common entry in a column

Hi, I have a file with 3 columns in it that are comma separated and it has about 5000 lines. What I want to do is find the most common value in column 3 using awk or a shell script or whatever works! I'm totally stuck on how to do this. e.g. value1,value2,bob value1,value2,bob... (12 Replies)
Discussion started by: Donkey25
12 Replies

2. Shell Programming and Scripting

Deleting column from a flatfile with delimiter

I have a set of flatfiles which have columns delimited by #. How can a particular column be deleted in all the flatfiles. All flatfiles have same number of columns. (5 Replies)
Discussion started by: rsprabha
5 Replies

3. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

4. Shell Programming and Scripting

Help with finding a string and printing value in the next column

Hi, been about 10 years since I've scripted, so very rusty and could use some quick help. I have a file that contains data like such: folder1 jondoe owner janedoe reader joeshmo none folder2 jondoe none janedoe none joeshmo owner folder3 jondoe owner folder4 janedoe owner joeshmo... (7 Replies)
Discussion started by: drewpark
7 Replies

5. Shell Programming and Scripting

Finding the last column value from a text file

Hi, I need to find out the last column value from a text file which is delimited by a tab. The issue here is the last column# for each record can be different i.,e, 1st record can have the last column as 15 and the second record can have the last column as "17". I have to search a string... (3 Replies)
Discussion started by: naveen_sangam
3 Replies

6. Shell Programming and Scripting

Finding the second last column value from a text file

Can any one tell me how to get the second last column value from the text file, which has different record size for each record. I know how to get the last column using awk and print statements, but I am unable to get the second last column value from the file. (4 Replies)
Discussion started by: naveen_sangam
4 Replies

7. Shell Programming and Scripting

Finding Maximum value in a column

Hello, I am trying to get a script to work which will find the maximum value of the fourth column and assign that value to all rows where the first three columns match. For example: 1111 2222 AAAA 0.3 3333 4444 BBBB 0.7 1111 2222 AAAA 0.9 1111 2222 AAAA 0.5 3333 4444 BBBB 0.4 should... (8 Replies)
Discussion started by: jaysean
8 Replies

8. UNIX for Dummies Questions & Answers

finding nearest value in a column

Hi, I have 2 files: file1: 1 ia 2 1 mn 6 1 sd 11 2 ny 3 2 ma 10 3 wa 7 3 ca 8 file2 1 mi 3 1 wi 5 2 pa 4 3 id 6 (2 Replies)
Discussion started by: peanuts48
2 Replies

9. Shell Programming and Scripting

Finding Nth Column

Please help me how can I display every nth field present in a "|" delimited file. Ex: If a have a file with data as a|b|c|d|e|f|g|h|k|l|m|n I want to display every 3rd feild which means the output should be c f k n Please help me. (1 Reply)
Discussion started by: ngkumar
1 Replies

10. Shell Programming and Scripting

Finding null column value using array

hi, Am trying to find a solution for finding a null column value inside a loop using array. for eg: two three five From the above array myarray,myarray and myarray having null values. But when am trying to check that space using some condition its not working. for (( i=0;... (4 Replies)
Discussion started by: rogerben
4 Replies
PR(1)							    BSD General Commands Manual 						     PR(1)

NAME
pr -- print files SYNOPSIS
pr [+page] [-column] [-adFmrt] [[-e] [char] [gap]] [-h header] [[-i] [char] [gap]] [-l lines] [-o offset] [[-s] [char]] [-T timefmt] [[-n] [char] [width]] [-w width] [-] [file ...] DESCRIPTION
The pr utility is a printing and pagination filter for text files. When multiple input files are specified, each is read, formatted, and written to standard output. By default, the input is separated into 66-line pages, each with o A 5-line header with the page number, date, time, and the pathname of the file. o A 5-line trailer consisting of blank lines. If standard output is associated with a terminal, diagnostic messages are suppressed until the pr utility has completed processing. When multiple column output is specified, text columns are of equal width. By default text columns are separated by at least one <blank>. Input lines that do not fit into a text column are truncated. Lines are not truncated under single column output. OPTIONS
In the following option descriptions, column, lines, offset, page, and width are positive decimal integers and gap is a nonnegative decimal integer. +page Begin output at page number page of the formatted input. -column Produce output that is columns wide (default is 1) that is written vertically down each column in the order in which the text is received from the input file. The options -e and -i are assumed. This option should not be used with -m. When used with -t, the min- imum number of lines is used to display the output. -a Modify the effect of the -column option so that the columns are filled across the page in a round-robin order (e.g., when column is 2, the first input line heads column 1, the second heads column 2, the third is the second line in column 1, etc.). This option requires the use of the -column option. -d Produce output that is double spaced. An extra <newline> character is output following every <newline> found in the input. -e [char][gap] Expand each input <tab> to the next greater column position specified by the formula n*gap+1, where n is an integer > 0. If gap is zero or is omitted the default is 8. All <tab> characters in the input are expanded into the appropriate number of <space>s. If any nondigit character, char, is specified, it is used as the input tab character. -F Use a <form-feed> character for new pages, instead of the default behavior that uses a sequence of <newline> characters. -h header Use the string header to replace the file name in the header line. -i [char][gap] In output, replace multiple <space>s with <tab>s whenever two or more adjacent <space>s reach column positions gap+1, 2*gap+1, etc. If gap is zero or omitted, default <tab> settings at every eighth column position is used. If any nondigit character, char, is specified, it is used as the output <tab> character. -l lines Override the 66 line default and reset the page length to lines. If lines is not greater than the sum of both the header and trailer depths (in lines), the pr utility suppresses output of both the header and trailer, as if the -t option were in effect. -m Merge the contents of multiple files. One line from each file specified by a file operand is written side by side into text columns of equal fixed widths, in terms of the number of column positions. The number of text columns depends on the number of file operands suc- cessfully opened. The maximum number of files merged depends on page width and the per process open file limit. The options -e and -i are assumed. -n [char][width] Provide width digit line numbering. The default for width, if not specified, is 5. The number occupies the first width column posi- tions of each text column or each line of -m output. If char (any nondigit character) is given, it is appended to the line number to separate it from whatever follows. The default for char is a <tab>. Line numbers longer than width columns are truncated. -o offset Each line of output is preceded by offset <spaces>s. If the -o option is not specified, the default is zero. The space taken is in addition to the output line width. -r Write no diagnostic reports on failure to open a file. -s char Separate text columns by the single character char instead of by the appropriate number of <space>s (default for char is the <tab> character). -T Specify an strftime(3) format string to be used to format the date and time information in the page header. -t Print neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quit printing after the last line of each file without spacing to the end of the page. -w width Set the width of the line to width column positions for multiple text-column output only. If the -w option is not specified and the -s option is not specified, the default width is 72. If the -w option is not specified and the -s option is specified, the default width is 512. file A pathname of a file to be printed. If no file operands are specified, or if a file operand is '-', the standard input is used. The standard input is used only if no file operands are specified, or if a file operand is '-'. The -s option does not allow the option letter to be separated from its argument, and the options -e, -i, and -n require that both arguments, if present, not be separated from the option letter. ERRORS
If pr receives an interrupt while printing to a terminal, it flushes all accumulated error messages to the screen before terminating. The pr utility exits 0 on success, and 1 if an error occurs. Error messages are written to standard error during the printing process (if output is redirected) or after all successful file printing is complete (when printing to a terminal). SEE ALSO
cat(1), more(1), strftime(3) STANDARDS
The pr utility is IEEE Std 1003.2 (``POSIX.2'') compatible. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy