sed Problem in Shellscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Problem in Shellscript
# 1  
Old 08-08-2008
sed Problem in Shellscript

Hi, i have a problem with sed

i want to substitude a / to ",""," in the following pattern: number/number

so if u have a file which contains -> "Streetname 9/8/6" it shouldn't substitude anything, only if it is "Streetname 9/6" to "Streetname 9","","6".

Maybe you can help me, i try so many patterns but i'm not really good in shellscript programming
# 2  
Old 08-08-2008
try this

sed -e 's/\//","","/g' filename
# 3  
Old 08-08-2008
this only replaces all / with ",""," but this is very bad for my final file!
my start file looks like this:
"Baumgasse 42/5"
"Prinz Eugen Strasse 34"
"Rudolf-Nurejew-Promenade 1/8/1"
and it needs to look like:
"Baumgasse","42","","5"
"Prinz Eugen Strasse","34"
"Rudolf-Nurejew-Promenade","1","8","1"

i dont want the whole shellscript for it (need to learn it) i just want to know how i can do my above stated problem.
i want to do it like this way sed 's!\( [0-9]*\)/\([0-9]*"\)!","","\1!g'
but i dont know how it works that he only replaces the / in the middle of the two patterns.
# 4  
Old 08-08-2008
Code:
$ cat file
Streetname 9/6
Streetname 9/6/6
$ sed 's/\( [0-9]*\)\/\([0-9]*"\)$/\1","","\2/' file
"Streetname 9","","6"
"Streetname 9/6/6"
$

# 5  
Old 08-08-2008
thank you very much, this solved my problem!
# 6  
Old 08-08-2008
ok got your problem try this....
sed -e 's/[0-9]/","&/1' -e 's/\//","","/g' filename
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed inside shellscript

Hi All, I am trying to use sed command inside a shell script. The same sed command is working on command line, however its not working while using inside a shell script. From various sources i found , it could be done by using -i option, but its not working as well. sed... (11 Replies)
Discussion started by: gotamp
11 Replies

2. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

3. Shell Programming and Scripting

Execution problem with the FTP shellscript

Hi Friends I am new to the shell script and i have a script which will connect to server enviornment which will read a file and will FTP to an another server location. But while executing this script FTP transfer is not occuring. But when I enter in FTP mode I am able to transfer the file... (5 Replies)
Discussion started by: Kannannair
5 Replies

4. Shell Programming and Scripting

Help with shellscript

I am new in shell script i want to convert .txt file in the format axsjdijdjjdk to a x s j d i j d j j d k (5 Replies)
Discussion started by: sreejithalokkan
5 Replies

5. Post Here to Contact Site Administrators and Moderators

help with backup shellscript

can any one advice on this.. create archive backup -yyyymmdd.tr.gzin the directory "backup" that includes the following directory " product/dev","product/uat"and product/maintain", yymmdd, stand for current date This archive needs to be perpared at 9PM every day Thanks advance (1 Reply)
Discussion started by: ksakil
1 Replies

6. Shell Programming and Scripting

if condition in shellscript

Hi All, I tried below code getting error. AD=0 ZERO=0 if then echo "AD is zero select another symbol" fi syntax error near unexpected token `fi' plz help me to solve this error (4 Replies)
Discussion started by: aish11
4 Replies

7. Shell Programming and Scripting

remove newline between two string with sed command in unix shellscript

I have a file (test.dat) which contains data like this 459|199811047|a |b |shan kar|ooty| 460|199811047|a |bv |gur u|cbe| but I need it like: 459|199811047|a |b |shankar|ooty| 460|199811047|a |b |guru|cbe| While reading the data from this file, I don't want to remove newline from the end of... (4 Replies)
Discussion started by: jcrshankar
4 Replies

8. Shell Programming and Scripting

Need help with shellscript

Hello. I am a novince at writing shell scripts but here is the question. I have to write a shell script that does the following: Once executed via crontab, the script should do the following: a. get date/time stamp in for format 10-MAR-05 and b. execute shell script my_script.sh (which... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

9. UNIX for Advanced & Expert Users

shellscript problem

hI, Pls consider the following shell script #!/bin/csh -f sqlplus tkyte/tkyte <<"EOF" > tmp.csh set serveroutput on declare a number:=5; begin dbms_output.put_line( 'a:='||a ); end; / spool off "EOF" The above script does the followin 1)it connects... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies
Login or Register to Ask a Question