Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

cbsm (Programmer) (OP)
15 Sep 06 7:29
Hello.
I am new to unix.
Using ksh.
I have this file in which I like to replace "CarRet" by a real carriage return ( or end of line or what ever it is).
ex :
Message1CarRetMessage2
should be
Message1
Message2
I tried a few things like :
sed 's\CarRet\/n\g' result : Message1/nMessage2
or 's/CarRet/'"$(printf '\015')"'/g' (not sure 15 is the correct number, but it didn't work anyways) result : Message1"$(printf '\015')"Message2
I tried sed 's/CarRet/\015/g'
error message : I know the reason is the way I wrote \015 but i do not know how to write it : I "use" 1 charcter for each digit, instead of having 1 character for the whole number - not sure how to explain this ...

Well, any idea is welcome !
Helpful Member!  feherke (Programmer)
15 Sep 06 7:37
Hi

CODE

master # echo 'Message1CarRetMessage2' | sed 's/CarRet/\n/g'
Message1
Message2

Feherke.
http://rootshell.be/~feherke/

cbsm (Programmer) (OP)
15 Sep 06 8:16
Actually I am using a sed file like so :
sed -n -f MySedFile.sed MyInputFile > MyOutputFile

and MySedFile is something like :

s/abc/def/g
s/CarRet/\n/g
s/X/x/g

where should I put the master # - and what is this ?

Thank you
feherke (Programmer)
15 Sep 06 8:34
Hi

Is my prompt. I include that in the codes in my posts to show that the following command was executed from the command prompt and its output follows.

I would not use the -n option. That means to not produce output automatically, only when a p command is executed.

Feherke.
http://rootshell.be/~feherke/

feherke (Programmer)
15 Sep 06 8:41
Hi

Maybe this examples explains better what I want to say about the outputing :

CODE

master # echo hello | sed 's/l/|_/g'
he|_|_o

master # echo hello | sed -n 's/l/|_/g'

master # echo hello | sed -n 's/l/|_/g;p'
he|_|_o

master # echo hello | sed 's/l/|_/g;p'
he|_|_o
he|_|_o

Feherke.
http://rootshell.be/~feherke/

cbsm (Programmer) (OP)
15 Sep 06 8:46
oh - I feel really stupid now ....

I tried and the result :
Message1nMessage2 ...
(I took everytthing out of my sed file but s/CarRet/\n/g and did not use the -n option)
feherke (Programmer)
15 Sep 06 9:02
Hi

Strange. Tell us what operating system and sed version you use.

Feherke.
http://rootshell.be/~feherke/

cbsm (Programmer) (OP)
15 Sep 06 9:12

Well .. not sure how to see all this ...

SunOS5.8 (I am logging to the Unix server from my Windows-PC)
as for the sed version ???
Helpful Member!  PHV (MIS)
15 Sep 06 9:19
And what about this ?
nawk '{gsub(/CarRet/,"\n");print}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

feherke (Programmer)
15 Sep 06 9:36
Hi

Quote (cbms):

as for the sed version ???
Ask it.

CODE

master # sed --version
GNU sed version 4.1.2
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
As Unix programs applies only POSIX standards, maybe your sed needs -v parameter instead of --version.

Feherke.
http://rootshell.be/~feherke/

cbsm (Programmer) (OP)
15 Sep 06 10:09

sed -v
sed -version
sed --v
sed --version
are all 'illegal option'

I will try PHV's solution also I am not to sure how ...
I let you know.
If it's not working, I will also try to work on the way my file is generated in the first place maybe there is something to do there ...

Many thanks for the help !
And I come back to you if I found a way ... or need more help !


KenCunningham (TechnicalUser)
15 Sep 06 10:23
Sounds like you don't have the GNU version of sed.

I don't mind people who aren't what they seem. I just wish they'd make their mind up.

Alan Bennett.

cbsm (Programmer) (OP)
15 Sep 06 10:41

PHV's solution did it !
I will try to found out more about nawk.
(I like to understand why something is working, or why not.)
p5wizard (IS/IT--Management)
15 Sep 06 11:44
on non-GNU, plain vanilla unix sed, you can't use \n, but you can go like this:

CODE

# echo 'Message1CarRetMessage2' | sed 's/CarRet/\
> /g'
Message1
Message2
#

the # and > in red are the PS1 and PS2 prompts, you don't type them.

in a script it would be

CODE

echo 'Message1CarRetMessage2' | sed 's/CarRet/\
/g'

Just make sure the bakslash '\' is the last character on that first line - this makes sed continue reading its commands on the next line. Other UNIX commands and the shells behave the same.

HTH,

p5wizard

bigoldbulldog (Programmer)
20 Sep 06 12:23
Here's another for old-fashioned sed:

CODE

sed -e :a -e 'G;s/\(.*\)\(Car\)\(.*\)\(\n\)/\1\4\3/;t a' -e 's/.$//'

This is probably better

CODE

sed -e '/Car/{' -e 'G' -e :a -e 's/\(.*\)\(Car\)\(.*\)\(\n\)/\1\4\3\4/;t a' -e 's/.$//' -e '}'
or

CODE

sed '/Car/{
  G
  :a
  s/\(.*\)\(Car\)\(.*\)\(\n\)/\1\4\3\4/
  t a
  /.$//
}'

Cheers,
ND smile

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close