Operating System - Tru64 Unix
1753727 Members
4463 Online
108799 Solutions
New Discussion юеВ

Re: Removing the first Charater in a text file

 
SOLVED
Go to solution
Marty Metras
Super Advisor

Removing the first Charater in a text file

I have a strange thing I want to do.
In our Apps when it greneates a text file for the printer it inserts a formfeed (Control L I think) causing an leading blank page on all our printers. If I turn off the Formfeed in the Apps then there is no page break at all and this is messy.
Here is what I want to do and need a little help.
The Apps has a Printer filter script that adds the the printer controls (like -onp, -o compress, etc). In here is could add a shortscript that removes the first charater if it is a formfeed.
My question is what is an easy way to remove just the first charater?
Must be an easy way to do this.
Marty
The only thing that always remain the same are the changes.
4 REPLIES 4
Mark Grant
Honored Contributor
Solution

Re: Removing the first Charater in a text file

how about something like this

#!/bin/sh
read a
a=`expr "$a" : ".\(.*\)"`
echo $a
while read a
do
echo $a
done

then run by piping your file into this script.
Probably prettier ways than this but this is first thing that came to mind.
Never preceed any demonstration with anything more predictive than "watch this"
Michael Schulte zur Sur
Honored Contributor

Re: Removing the first Charater in a text file

Hi Marty,

the following c programme you can also use as filter, if you have only this app printing, otherwise use command < textfile.
It filter a form feed/line feed in the first line.

Michael

#include "stdio.h"

void main(void)
{
ushort c;
ushort d;

d = 1;
while(!feof(stdin))
{
c = getchar();
if (d == 1)
{
if (c == 12)
{
c = getchar();
if (c == 10)
{
d = 0;
c = getchar();
}
}
}
putchar(c);
d = 0;
}
}
Marty Metras
Super Advisor

Re: Removing the first Charater in a text file

Thanks guys.
I got it working.

Thanks for the help.
Marty
The only thing that always remain the same are the changes.
Gary Hansford
Frequent Advisor

Re: Removing the first Charater in a text file

Marty,

Here's the way we do it... (for reference), then we pipe it into the print filter ...

sed -e "1 s/^L//g;\$ s/^L//g" ${file}

Gary