Sponsored Content
Full Discussion: File Handling
Top Forums UNIX for Dummies Questions & Answers File Handling Post 302760955 by Yoda on Thursday 24th of January 2013 11:38:51 PM
Old 01-25-2013
Quote:
Originally Posted by Gurkamal83
I need to cut the files into multiple files of 1000 records and should have the same header and trailer as the original files.
You said that you want the same header and trailer as the original file!

By the way I missed skipping header & trailer, which you can do using awk:
Code:
lines=$( wc -l < filename )
awk -v L=$lines 'NR>1&&NR<L' filename > filename_data
split -d -l 1000 filename_data filename_out

Use wc to calculate line count and append it as trailer to each file:
Code:
head -1 filename > header

for file in filename_out*
do
   cat header ${file} > tmp
   wc -l < ${file} >> tmp
   mv tmp ${file}
done

 

10 More Discussions You Might Find Interesting

1. Programming

File Handling in C

Hi all, I have a problem in handling files through C. here is the problem im having: i will query the database (for instance consider employees table ) for empno,ename,job,salary fields.The query returns me some 100 of rows. now i need to place them in a file in row wise pattern as they... (3 Replies)
Discussion started by: trinath
3 Replies

2. Programming

file handling

Hi all, I got a little issue here. Imagine that I have more than one process accessing one file. Is it possible to know which process(es) are accessing that file when I open the file?? Thanks for the help. Best regards, Ernesto (2 Replies)
Discussion started by: ninjanesto
2 Replies

3. UNIX for Advanced & Expert Users

File Handling

Hi, I have a log file which runs into 3 to 5 GB. We store this typically for 6 months. When a new month starts we move the previous month into a 9 month back up log (file.9m) and delete the last month of the 9 month back up. Iam using awk to find the data and cat to join the files like... (3 Replies)
Discussion started by: baanprog
3 Replies

4. UNIX for Advanced & Expert Users

please help me in file handling

sir i have to get first line from a file for example >cat file1 abc zxc asd adsf from that file1 i need only first line expected result >abc please help me ! (1 Reply)
Discussion started by: ponmuthu
1 Replies

5. UNIX for Advanced & Expert Users

File handling

my input for a script is another csv file but in that file say 7 lines are there ... how can i get line by line to that input for example : >cat link.csv www.yahoo.com,yahoo www.google.com,google www.unix.com,unix another file in that file i need to ping the above links ... (2 Replies)
Discussion started by: ponmuthu
2 Replies

6. Shell Programming and Scripting

UNIX File handling -Issue in reading a file

I have been doing automation of daily check activity for a server, i have been using sqls to retrive the data and while loop for reading the data from the file for several activities. BUT i got a show stopper the below one.. where the data is getting store in $temp_file, but not being read by while... (1 Reply)
Discussion started by: KuldeepSinghTCS
1 Replies

7. Programming

Perl help for file handling

$# some text $$ some text $@ some text $$. some text Mg1 some text Mg2 some text . . . Mg10 some text The above 10 lines are to be extracted except the lines starting from $#,$$.,... (4 Replies)
Discussion started by: baig.abdul
4 Replies

8. Shell Programming and Scripting

ksh file handling

Specifically on RHEL 5.7. When does the underlying ksh process open and close files? Every time they're accessed, or as little as possible? Say you have some script like: CreateFiles() { grep "<VALUE1>" ${infile} >> ${outfile} grep "<VALUE2>" ${infile} >> ${outfile} ...... (4 Replies)
Discussion started by: CarloM
4 Replies

9. UNIX for Dummies Questions & Answers

File handling

I have a file 1 298167 298168 1093209 1093210 1422663 I want to write a code where in I want to read contents of above file like first read is 1 second read is 298167 Substract second read from first and if this is greater than or less than 99,999. Similarly I want to traverse thru... (3 Replies)
Discussion started by: Guru148
3 Replies

10. Shell Programming and Scripting

File handling

Hi All, I need to extract the data from the text file. The data of the text file is shown below #L 0.000017 4.329939 0.000017 4.716267 r7.9 P 1 1;Net=IN32 The extracted data should be IN32. Could anyone help to script in c shell.? (4 Replies)
Discussion started by: gopishrine
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 07:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy