ksh scripted sed needs a control J - but I can't write the script!

ksh scripted sed needs a control J - but I can't write the script!

Post by didd » Fri, 13 May 2005 20:43:50



Hi - writing a ksh script to parse a datafile and alter various
characters to control characters (on a solaris 9 system if that makes a
difference).

For example, a line starting with a "1" needs to have the 1 replaced by
a linefeed i.e. Control L...  no problems, I write my sed command

sed 's/^1/^L/' file > tmpfile

(where ^L is actually control L as typed in vi)

However, similarly "0" needs to be replaced by a linefeed - control J.

But of course I can't actually enter control J in vi (my editor of
choice) not even if I precede it with control V.  All that happens is I
get a real line feed within the script which then (of course) does not
parse syntactically when I try and run it.

sed works fine this way oif done from the command line but thgis needs
to be scripted so it runs via cron...

How can I script this such that my zeroes in column one of a line in a
file gets replaced by a control J?

cheers!

ian

 
 
 

ksh scripted sed needs a control J - but I can't write the script!

Post by Icarus Sparr » Fri, 13 May 2005 21:09:03



> However, similarly "0" needs to be replaced by a linefeed - control J.
> How can I script this such that my zeroes in column one of a line in a
> file gets replaced by a control J?

sed 's/^0/\
/' file > tmpfile

 
 
 

ksh scripted sed needs a control J - but I can't write the script!

Post by Bill Marcu » Fri, 13 May 2005 23:45:07


On 12 May 2005 04:43:50 -0700, didds

> Hi - writing a ksh script to parse a datafile and alter various
> characters to control characters (on a solaris 9 system if that makes a
> difference).

> For example, a line starting with a "1" needs to have the 1 replaced by
> a linefeed i.e. Control L...  no problems, I write my sed command

> sed 's/^1/^L/' file > tmpfile

> (where ^L is actually control L as typed in vi)

> However, similarly "0" needs to be replaced by a linefeed - control J.

> But of course I can't actually enter control J in vi (my editor of
> choice) not even if I precede it with control V.  All that happens is I
> get a real line feed within the script which then (of course) does not
> parse syntactically when I try and run it.

> sed works fine this way oif done from the command line but thgis needs
> to be scripted so it runs via cron...

> How can I script this such that my zeroes in column one of a line in a
> file gets replaced by a control J?

sed 's/^0//' file | tr '' '\n' >newfile
should be a character that does not appear in the original file.

--
Test-tube babies shouldn't throw stones.

 
 
 

ksh scripted sed needs a control J - but I can't write the script!

Post by John W. Krah » Sat, 14 May 2005 03:12:07



> Hi - writing a ksh script to parse a datafile and alter various
> characters to control characters (on a solaris 9 system if that makes a
> difference).

> For example, a line starting with a "1" needs to have the 1 replaced by
> a linefeed i.e. Control L...  no problems, I write my sed command

> sed 's/^1/^L/' file > tmpfile

> (where ^L is actually control L as typed in vi)

> However, similarly "0" needs to be replaced by a linefeed - control J.

> But of course I can't actually enter control J in vi (my editor of
> choice) not even if I precede it with control V.  All that happens is I
> get a real line feed within the script which then (of course) does not
> parse syntactically when I try and run it.

> sed works fine this way oif done from the command line but thgis needs
> to be scripted so it runs via cron...

> How can I script this such that my zeroes in column one of a line in a
> file gets replaced by a control J?

perl -pe's/^1/\f/;s/^0/\n/' file > tmpfile

John
--
use Perl;
program
fulfillment

 
 
 

ksh scripted sed needs a control J - but I can't write the script!

Post by didd » Sat, 14 May 2005 17:04:50


Many thanks to all, and especially John - great solution mate!

ian

 
 
 

1. 'script' in a cron initiated ksh script

Can I include in a ksh script that is run via cron the "script" command
to capture the screen output to a log file?  It is my understanding that
cron initiates processes in the background. So, is there going to be
"screen output" anyway?

The script in question is executing a database application program to
build some small files from the primary database transaction files, and I
need to capture the output in the event that there is an error during the
program run:

#!/usr/bin/ksh
#
script -a log.txt
cd [directory name here]
/usr/uv/bin/uv<<...
RUN BP BP130.1.H.1
...
#end of script

All opinions appreciated.
--

The above opinions are mine, not my employer's.

2. Xfree Emulate3buttons

3. . sed script offered, sed script wanted

4. HP LasterJet 2628A setup

5. Need help getting started on a script (awk, sed, ksh ?)

6. Multiple IP on Apache

7. Need help writing script in ksh

8. [Fwd: XAnim compile problem]

9. Need help with 'sed' in C shell scripts

10. need help with 'sed' script

11. PROBLEM: 'sed' script 's/^ /\n/' not working properly

12. returning control back to my script after spawning another script

13. SED: Converting 5 line script into 1 line script