Stucked with sed, how to replace /


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stucked with sed, how to replace /
# 8  
Old 03-30-2012
@Shailesh,

All the rows.

@Corona,

I have already given a code snippet above. You can use that to test.

Regards,
Manu
# 9  
Old 03-30-2012
use this
Code:
sed s:dmp_file_lst:`ls \/opt\/abcd\/efgh\/export_dump\/$DMP_FILE_NM*.dmp | tr "\n" " " `:g

this will replace dmp_file_lst with space separated file names
# 10  
Old 03-30-2012
Quote:
Originally Posted by manubatham20
I have already given a code snippet above. You can use that to test.
Posting a program which doesn't do what you want cannot tell us what you do want. The computer can't tell your intent from it, neither can we.

The complete lack of example input and example output makes it even harder to guess. We need to see what success would look like, what you actually want.

Please post some of the input you have, and some of the output you want -- not the bad output, what good output would look like, so we don't have to guess what you want.

Without that, getting the answer you want from anyone is a matter of pure luck.
# 11  
Old 03-30-2012
Smilie

True. But I need to print in seprate lines, not space seprated (as it will disorder formatting)

Any other idea???

Thanks.
# 12  
Old 03-30-2012
it's very unclear what outcome you desire, unless you provide info as asked by @Corona688
# 13  
Old 03-30-2012
Hmmm, ok.

I have a directory structure like below:

a/b/c

Code:
mkdir -p /a/b/c

inside that there are many files like:

d1
d2
d3
d4

Code:
touch d1 d2 d3 d4

Create a file unix_test, give execute permissions and put the below in it:

Code:
#!/bin/sh

sed "
   s/dmp_file_nm/abc.dmp/g
   s:dmp_file_lst:`ls -1 \/a\/b\/c\/d*`:g
   s/log_file_nm/xyz.log/g" unix_a > unix_b

create another file unix_a and put the following:

Code:
dmp_file_nm
dmp_file_lst
log_file_nm

After executing unix_test, desired output is:

Code:
abc.dmp
d1
d2
d3
d4
xyz.log

Please help me to achieve the same.

Thanks for your suggestions and concerns.
This User Gave Thanks to manubatham20 For This Post:
# 14  
Old 03-30-2012
Quote:
Originally Posted by manubatham20
Hmmm, ok.

I have a directory structure like below:

a/b/c

Code:
mkdir -p /a/b/c

inside that there are many files like:

d1
d2
d3
d4

Code:
touch d1 d2 d3 d4

Create a file unix_test, give execute permissions and put the below in it:

Code:
#!/bin/sh

sed "
   s/dmp_file_nm/abc.dmp/g
   s:dmp_file_lst:`ls -1 \/a\/b\/c\/d*`:g
   s/log_file_nm/xyz.log/g" unix_a > unix_b

create another file unix_a and put the following:

Code:
dmp_file_nm
dmp_file_lst
log_file_nm

After executing unix_test, desired output is:

Code:
abc.dmp
d1
d2
d3
d4
xyz.log

Please help me to achieve the same.

Thanks for your suggestions and concerns.
change your 2.line to this Smilie

s:dmp_file_lst:`ls -1 \/a\/b\/c\/d*`:g to
Code:
 s/dmp_file_lst/$(ls -1 /a/b/c/d*|sed 's/.*\///;'|sed ':a;N;s/\(.*\)\n\(.*\)/\1\\n\2/;ta')/

regards
ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed replace?

Hello. I have this file: XXXX 1 AAAA 2 BBBB 3 CCCC 4 DDDD YYYY 1 AAAA 2 BBBB 3 CCCC 4 DDDD Desired output: XXXX AAAA XXXX BBBB XXXX CCCC XXXX DDDD YYYY AAAA (5 Replies)
Discussion started by: jimmyf
5 Replies

2. IP Networking

Totally stucked in ssh port forwarding

Hello my friends , i am totally stuck in ssh port forwarding topic i had learn iptables and other networking topic without any problem but ssh port forwarding is headache 1. local port = what is this ? is this incoming traffic or outgoing traffic 2. remote port = same as above 3. dynamic... (2 Replies)
Discussion started by: rink
2 Replies

3. Shell Programming and Scripting

sed replace

Hi, i have a file as give below >cat sample_file param1 val1 2012-06-19 ##there can be one or more space after 2012-06-19 in the above file i want to replace val1 with a with value passed through a variable... below is the command i tried >parval='param1 val2' >par1=param1 >sed... (3 Replies)
Discussion started by: midhun19
3 Replies

4. Shell Programming and Scripting

Replace with sed

Hi, I have values in a file at Place $1 as AmericanDollar, AustralianDollar, Singapore1Dollar and so on on various rows. I want to replace Dollar with Pound for all those records where no numeric character is present in the string. Means in above mentioned values 'Singapore1Dollar' should not be... (11 Replies)
Discussion started by: DannyMirashi
11 Replies

5. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

6. UNIX for Dummies Questions & Answers

sed - replace $

my script: amount1=`tail /tmp/file1.txt` amount2=`tail /tmp/file2.txt` sed -e 's/'${amount2}'/'${amount1}'/g' filename1 > filename2 what did i do wrong ? i just want to replace amount1 with amount2 value. (2 Replies)
Discussion started by: tjmannonline
2 Replies

7. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

8. Solaris

Solaris box V440 got stucked

Hi Friends, My solaris box V440 got stucked. I couldn't accessit from the remote console. Finally i restarted the box. Can you tell me what are the ways we can find out the issues and what are the logs we can check other than /var/log/messages. Thanks Jinu (1 Reply)
Discussion started by: Jinu
1 Replies

9. Shell Programming and Scripting

using sed to replace ' with `

Dear All, I am writting a shell script program on AIX server version 5.3 in which I am doing cleaningprocess for files in which I am trying to replace ' with ` . and for this I am using following command: sed -e 's//$/g' -e 's/\\/\//g' -e 's/'/`/g' $file >>... (2 Replies)
Discussion started by: mr_dba01
2 Replies

10. Shell Programming and Scripting

How to replace using SED?

Hi, I want to change a particular string in a file with another string. This is part of a larger script file. I m using SED for this purpose: sed -e 's/hostname.domainname/${HOST}.${DOMAIN}/g' $sed_file>$tmp_file Where the occurance hostname.domainname has to be replaced with the... (4 Replies)
Discussion started by: mahatma
4 Replies
Login or Register to Ask a Question