problem in replacing asterisk in sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in replacing asterisk in sed
# 1  
Old 06-12-2009
problem in replacing asterisk in sed

Hi all,

Sed is the one which always trobules me Smilie

here is my input :

Code:
 
*** it industry need to be evolved *** in the world and hope so *** to be dream

the output i am expecting is :
Code:
 
*** it industry need to be evolved
*** in the world and hope so 
*** to be dream

here is what i have tried

Code:
TESTING>sed '/ \*\*\* / i\
>
> ' ravi_test.txt

here one line is inserted before the first "***" ( ofcourse it does not follwed spaces as specified in the condition.

One more doubt : when using "tr" to replace the "\n" with " " , further i can't use this output in a filter to sed as sed expects "\n" at the end to consider it as a line ?.. any clue on how to use "tr" in this case( have to retain the last "\n")

thanks and regards
Panyam
# 2  
Old 06-12-2009
Something like this?

Code:
sed 's/ \*\*\*/\
\*\*\*/g'

Regards
# 3  
Old 06-12-2009
if you have Python
Code:
#!/usr/bin/env python
for line in open("file"):
    line=line.strip().split("***")
    for i in line:
        if i!="" : print "***"+i

output
Code:
# ./test.py
*** it industry need to be evolved
*** in the world and hope so
*** to be dream

# 4  
Old 06-12-2009
With awk:

Code:
awk '{gsub(" \*\*\*","\n***")}1'

Regards
# 5  
Old 06-12-2009
Thanks Franklin and ghostdog74. It's worked fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

SED - how do I convert a decimal number to asterisk

Hi, My animal ID's have two zeros in them and are also converting to asterisk. I only need to change the zero values in columns two and three. I would appreciate any help. This is my data structure: head phendata.txt 201008809 0.0 0.0 201008810 0.0 0.0 201008813 0.0 0.0 201014103... (6 Replies)
Discussion started by: lel7lel7
6 Replies

2. Programming

Problem on acquiring arguments with asterisk '*' (C language)

Hi everybody, I wrote a simple C programm on Unix (HP-UX). Initially, it has to acquire some arguments by command line and print them on video. I use: printf("%s\n",argv); where 'i' represents the numner of arguments in a 'for' cycle. Problems begin when I pass a parameter containing '*'... (3 Replies)
Discussion started by: D4vid
3 Replies

3. Shell Programming and Scripting

sed inside sed for replacing string

My need is : Want to change docBase="/something/something/something" to docBase="/only/this/path/for/all/files" I have some (about 250 files)xml files. In FileOne it contains <Context path="/PPP" displayName="PPP" docBase="/home/me/documents" reloadable="true" crossContext="true">... (1 Reply)
Discussion started by: linuxadmin
1 Replies

4. Shell Programming and Scripting

problem with sed while replacing a string with another

Hi, I have a line something like this sys,systematic,system I want to replace only the word system with HI I used sed for this as below echo sys,systematic,system | sed 's/system/HI/' but I got output as sys,HIatic,system I wanted output as sys,systematic,HI Please tell me... (9 Replies)
Discussion started by: friendyboy
9 Replies

5. Shell Programming and Scripting

SED: Replacing $1 with $2 escape problem

Hi all, I have a script which uses sed to replace one string with another. The problem is, the string to be matched, and its replacement are coming in as two command line arguments $1 and $2 $1 and $2 can be absolutely anything, but both should be treated purely as strings. My sed command... (7 Replies)
Discussion started by: mark007
7 Replies

6. UNIX for Dummies Questions & Answers

sed problem replacing long strings

Hi all, I have a script which uses sed to replace one string with another. The problem is, the string to be matched, and its replacement are coming in as two command line arguments $1 and $2 $1 and $2 can be absolutely anything, but both should be treated purely as strings. My sed command... (1 Reply)
Discussion started by: mark007
1 Replies
Login or Register to Ask a Question