Add missing linefeeds between formfeeds in reports


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add missing linefeeds between formfeeds in reports
# 1  
Old 05-24-2012
Question Add missing linefeeds between formfeeds in reports

I need to take a report text file that is output from vendor software and there are some pages which have less then the normal amount of lines. I need to add these missing line feeds as there is a merge program that reads this file in fixed character and line mode template to output the final PDF report.
To state more simply there is a text file with 65 lives beteen each form feed and then randomly there is a page with 64 lines so I need to add in the missing line feed.
# 2  
Old 05-24-2012
I think awk can do this. Set the record separator as form-feed, and set the field separator as newline, so every 'line' is an entire page, and every 'field' is an entire line.

NF thus becomes the count of lines. And you can just set NF, then print. It will happily fill linefeeds between blank fields.

Requires nawk or gawk unless you're on Linux.

Code:
# Proof of principle.  Each 'block' separated by form-feed(\014)
# gets stretched to 5 lines.  Form-feed is not printed so the terminal doesn't erase itself.
printf "a\n\014b\n\014c\nd\ne\n\014" | awk -v RS="\014" -v FS="\n" -v OFS="\n" -v ORS="\n" '{ NF=5 } 1'
a




b




c
d
e


# Command you'd actually run:
$ awk -v RS="\014" -v FS="\n" -v OFS="\n" -v ORS="\n\014" '{ NF=65 } 1' input > output

If your document uses carriage returns, change FS, OFS, and ORS so \n is \r\n.
# 3  
Old 05-24-2012
In addition: awk should know RS='\f'
# 4  
Old 05-24-2012
when I run in HPUX
Code:
HP-UX FRHGLIS1@FRH:/sunquest/lab/reports/hpf/SAVE # awk -v RS="\014" -v FS="\n" -v OFS="\n" -v ORS="\n\014" '{ NF=65 } 1' in > out
awk: Input line                      cannot be longer than 3,000 bytes.
 The source line number is 1.
HP-UX FRHGLIS1@FRH:/sunquest/lab/reports/hpf/SAVE #

So there must be more than 300 bytes per page or the formfedd RS is not recognized
same with "\f"
Code:
HP-UX FRHGLIS1@FRH:/sunquest/lab/reports/hpf/SAVE # awk -v RS="\f" -v FS="\n" -v OFS="\n" -v ORS="\n\014" '{ NF=65 } 1' in > out
awk: Input line                      cannot be longer than 3,000 bytes.
 The source line number is 1.


Last edited by Corona688; 05-24-2012 at 06:09 PM..
# 5  
Old 05-24-2012
Some UNIX systems keep mouldy old pre-nawk versions of awk around for compatibility reasons. But they almost always have the real deal available as nawk.

Which is why I said "requires nawk or gawk". Smilie

I use Linux, which doesn't have any 'nawk' executable at all, since the general-purpose awk for GNU (aka GNU awk, aka gawk) is nawk-compatible.

Last edited by Corona688; 05-24-2012 at 06:21 PM..
# 6  
Old 05-24-2012
awk on HPUX is POSIX compliant and so should be based on nawk. Some awks for some reason need to have the fields recalculated first ($1=$1). Combining this with Corona688's suggestion, try this:
Code:
awk '{$1=$1}NF=65' FS='\n' OFS='\n' RS='\f' ORS='\f'

I did not use a newline in ORS, since I think 65 lines per pages, should mean 64 newlines characters before the form feed, no?

-- edit --
OK, I noticed that the message indicates the the record can not be longer than 3000, that means we probably cannot use a form feed as a record separator for that reason...

Last edited by Scrutinizer; 05-24-2012 at 07:11 PM..
# 7  
Old 05-24-2012
Try this:
Code:
awk '{n++} /^\f/{for(i=n;i<p;i++)print x; n=1}1' p=65 infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add missing date and time in a bash script?

Hi Again, I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file. INPUT 2016-01-13 01:33 10 2016-01-13 01:31 10 2016-01-13 01:30 10 2016-01-13 01:29 10 2016-01-13 01:28 10 2016-01-13 01:27 10 2016-01-13 01:26 10 2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies

2. Shell Programming and Scripting

Add word for a missing column

Hi team... I need some help/advise on adding a word for a missing column. I have a file as below. Rep N1 Forever Limited 2015 Rep N2 Limited 2016 since 2nd content is 3 lines missing one line so i need to make this like Rep N1 Forever (3 Replies)
Discussion started by: newbee5
3 Replies

3. Shell Programming and Scripting

How to add missing value?

Hi Gurus, I have a txt file. some record missed 2nd colum value, I need put default value into the file. ex: below file, first 4 records, missed one column (only 4 columns. it should be 5) $cat missedfield aaa,bbb,ccc,fff aaa,bbb,ccc,ddd 111,222,333,444 111,222,333,444... (3 Replies)
Discussion started by: ken6503
3 Replies

4. Shell Programming and Scripting

WARNING! 16126 bare linefeeds received in ASCII mode

I am doing FTP from a server and getting below ERROR:WARNING! 16126 bare linefeeds received in ASCII mode File may not have transferred correctly. I looked into web and found that I may need to change the mode to binary, but when I do so the records are not in readable format...So need the file... (10 Replies)
Discussion started by: joshilalit2004
10 Replies

5. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

6. Solaris

[solved]Config/enable_mapping missing, how to add?

Issue resolved by upgrading from solaris 11 to solaris 11.1 I would like to enable network mapping. While using instructions from: https://blogs.oracle.com/VDIpier/entry/solaris_11_changing_the_hostname To change my hostname I noticed I am missing the enable mapping bool. What it should... (0 Replies)
Discussion started by: taltamir
0 Replies

7. UNIX Desktop Questions & Answers

merging files and add missing rows

hello all, I have files that have a specific way for naming the first column they are make of five names in Pattern of 3 Y = (no case sensitive) so the files are names $Y-$Y-$Y or $X-$Y-$Z depending how we look they only exist of the pattern exist now I want to create a file from them that... (9 Replies)
Discussion started by: A-V
9 Replies

8. Shell Programming and Scripting

Help with removing embedded linefeeds

Greetings all, i have csv file with pipe separated columns SSN|NAME|ADDRESS|FILLER 123|abc|myaddress|xxx 234|BBB|my add ress broken up|yyy In the example above, the second record is broken into multiple lines. I need to keep going until I find a "|" since this issue is with the... (14 Replies)
Discussion started by: stayalive
14 Replies

9. Shell Programming and Scripting

Add missing times

Not sure about the title if someone has a better name for it please lemme know and I will edit the title. I have several (10+ files) which look something like: File 1: 12/28/2009 04:0 8 12/28/2009 04:4 4 12/28/2009 05:0 4 . . . File 2: 12/28/2009 04:1 7 12/28/2009 04:2 3... (2 Replies)
Discussion started by: jstrangfeld
2 Replies

10. Shell Programming and Scripting

i need to add missing delimiters...

ladies, gents.. say i have a file that should have 10 fields... (9 delimiters) some records have 10 fields, some have 5 some have 8, etc.. nothing consistent, but i need my file to have 9 delimiters on each line, even if its null fields.. how can i go line by line and add the correct... (2 Replies)
Discussion started by: obarrett
2 Replies
Login or Register to Ask a Question