LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-01-2006, 12:12 PM   #1
Pete.Hanson@jacobs.c
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
sed command help...


I need to convert a report file so that it will print correctly when transferred to an MVS printer. I am working on AIX 5.3 and the source report looks like this (the report does have CRLF line terminators)

Data Line 1 CRLF
Data Line 2 CRLF
Data Line 3 CRLF
FFCRLF
Data Line 1 CRLF

The problem is that the first line of every page of the report begins on second line of each page instead of the first line of each page.

I would like to execute a sed command (or any other command) to convert the data to (case 1):

Data Line 1 CRLF
Data Line 2 CRLF
Data Line 3 CRLF
FFData Line 1 CRLF

or to this (case 2):

Data Line 1 CRLF
Data Line 2 CRLF
Data Line 3 FFData Line 1 CRLF

So for case 1, I would like to convert every occurance of FFCRLF to FF (removing the CRLF). And for case 2, I would like to convert every occurance of CRLFFFCRLF to FF (removing the CRLF immediately before and immediately after the FF.

Thanks for your help!!!
 
Old 06-01-2006, 01:21 PM   #2
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
I guess that 'FF' is a special character, and I didn't bother to look for its escape sequence. But in principle, you can use sed's N command to include the next line as follows:
Code:
sed -e '/^FF\r$/{N;s/\r\n//}'
Here each line consisting of 'FF' and CR only is matched, the 'N' command appends to next line to the buffer, and CRLF is removed from the resulting buffer content.
 
Old 06-01-2006, 08:09 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
FF=formfeed ; S
ee here for the ASCII codes : http://www.bbdsoft.com/ascii.html, although I always though MVS used EBCDIC.
You might find this useful: http://www.natural-innovations.com/c...ciiebcdic.html
 
Old 06-02-2006, 05:37 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
try

Code:
perl -pe 's/\f\r\n/\f/s'
or
Code:
perl -pe 's/\f\r\n/\f\r/s'
 
Old 06-02-2006, 10:08 AM   #5
Pete.Hanson@jacobs.c
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your help...

It turns out that the source data, on AIX is:

Data Line 1 CRLF
Data Line 2 CRLF
Data Line 3 CRLF
FFData Line 1 CRLF <=== FF is a form feed.

I need to convert it to:

Data Line 1 CRLF
Data Line 2 CRLF
Data Line 3 FFData Line 1 CRLF

So I need to delete the CRLF that preceeds every form feed (CRLFFF to FF). This is joining 2 lines together - the line with the form feed to the previous line.

The perl command is simple, but it doesn't do the job:

perl -pe 's/\r\n\f/\f/s'

... does not work - no changes are made.

Thanks again for your help...
 
Old 06-02-2006, 10:09 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
can't you post real data?
 
Old 06-02-2006, 11:32 AM   #7
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Try dos2ux or dos2unix to convert your DOS linefeeds to unix.
sed can clean up the FF's as well
Code:
sed 's/^L$//'
^L is really the ctrl-L keypress.... I just wrote it so you could see it.
 
Old 06-02-2006, 02:35 PM   #8
Pete.Hanson@jacobs.c
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
sed question...

Here is some real data. The source file looks like this:

Data Line 1
Data Line 2
Data Line 3
♀Data Line 1

The file should end up looking like this:

Data Line 1
Data Line 2
Data Line 3♀Data Line 1

Hopefully the lines are still terminated with CRLF and not only LF here.

I want to convert every occurance of x'0D0A0C' to x'0C'. The goal is to remove the CRLF that proceeds every formfeed. This is joining the line containing the formfeed to the previous line.

Thanks again for your help...
 
Old 06-02-2006, 06:53 PM   #9
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Talking

Lean back and enjoy:
Code:
tac  | rev | sed -e "/\f/{N;s/\f\n\r/\f/}" | rev | tac
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed command Kalyani1 Linux - Software 28 12-07-2005 12:48 PM
sed command rharris72 Programming 6 11-20-2005 09:26 PM
sed command pazvant Linux - Software 2 05-09-2004 01:58 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 12:27 PM
sed command kwigibo Linux - General 3 04-21-2002 05:11 PM


All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration