sed pattern substitution issue?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed pattern substitution issue?
# 1  
Old 03-16-2011
sed pattern substitution issue?

Hello everyone ...
I'm going crazy, I hope some of you can help me ...

I have to replace a line in a crontab like this:

Code:
5 2 * * 2 root backupdat

with this:

Code:
5 5 * * 3 root backupdat


the command I use is the following:


Code:
sed -i.bak -e 's/5 2 * * 2 root backupdat/5 5 * * 3 root backupdat/' /etc/crontab

why can not replace that line?
something wrong?

thanks a lot
# 2  
Old 03-16-2011
Try this:
Code:
's/5 2 \* \* 2 root backupdat/5 5 * * 3 root backupdat/' /etc/crontab

This User Gave Thanks to tene For This Post:
# 3  
Old 03-16-2011
Quote:
Originally Posted by tene
Try this:
Code:
's/5 2 \* \* 2 root backupdat/5 5 * * 3 root backupdat/' /etc/crontab

excellent!
just not enough, let me explain better ...
I want to replace the line coming out from a grep, so I can not insert \ before *
how can I solve this problem?

thanks again
# 4  
Old 03-16-2011
This command will give you escaped * from your grep command. Then use it in the final sed command.
Code:
grep <pattern> <file> | sed 's/*/\\*/g'

This User Gave Thanks to tene For This Post:
# 5  
Old 03-16-2011
Quote:
Originally Posted by tene
This command will give you escaped * from your grep command. Then use it in the final sed command.
Code:
grep <pattern> <file> | sed 's/*/\\*/g'

it is true .. I had not thought of that!
Thank you very much and sorry for my ignorance ...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - pattern match - apply substitution

Greetings Experts, I am on AIX and in process of creating a re-startable script that connects to Oracle and executes the statements. The sample contents of the file1 is CREATE OR REPLACE VIEW DB_V.TAB1 AS SELECT * FROM DB_T.TAB1; .... CREATE OR REPLACE VIEW DB_V.TAB10 AS SELECT * FROM... (9 Replies)
Discussion started by: chill3chee
9 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. Shell Programming and Scripting

Substitution Issue with nawk

Hi, I'm trying to reformat some badly formatted XML that I've extracted from Oracle clob columns using the following nawk command: nawk '{gsub(/&lt;/,/>\n/); print}' test.raw > test.xml the substitution executes fine, but instead of subbing &lt; with > followed by newline, it subs the &lt; with a... (3 Replies)
Discussion started by: sffuji
3 Replies

4. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

5. UNIX for Dummies Questions & Answers

Substitution mid pattern?

Hi there, I have a file that goes like this: b_cdbc_db_cd_bcd_aaa-bcd_cd That type of format, for many lines. What I want to do is enter a new line character for after the _ I write an expression to find "_...-" fine, but I don't know how to substitute this to be: "_\naaa-" - where... (1 Reply)
Discussion started by: maximus73
1 Replies

6. Shell Programming and Scripting

Issue with substitution using sed

Hi all Having issue with substitution using sed Trying to assign the absolute path of the file to the variable 'floc' returned by the find command floc=`find / -name $fname` eg cat $floc '/root/samplecheck/myfile' I want to replace '/' with '->' in the 'floc' i am using the below sed... (2 Replies)
Discussion started by: amithsebkanattt
2 Replies

7. Shell Programming and Scripting

Issue in substitution

Hi , I have have file which has following structure 01aaaa88888000-9999 01ssss77777000-0991 01ssss7777700000991 02ssss7777700000991 The record 01 is corrupt as value from 12th field to 19th should be positive or start with - however it is 000-9999 it should be -0009999 i need to... (4 Replies)
Discussion started by: test_user
4 Replies

8. Solaris

Variable Substitution Issue

#!/bin/ksh VAR_ONE=HELLO TEMP=ONE echo $VAR_${TEMP} ## Output is: ONE Hi, I want the output to echo HELLO and not ONE as the above script does. I know I am missing something with dollar substitution. Can anyone help me out ? Thanks. Cal (4 Replies)
Discussion started by: calredd
4 Replies

9. Shell Programming and Scripting

pattern match and substitution, can you help?

pattern match and substitution, can you help? file named test.txt I want to replace all the words Event with the word Fatal in all lines containing the word ERR - but I also want to keep the output of the other lines not matching ERR Test.txt: Event 13 INF egegegege Event 14 INF... (4 Replies)
Discussion started by: frustrated1
4 Replies

10. UNIX for Dummies Questions & Answers

vi/vim : complex pattern substitution

I use vim. I have a lot of SQL queries to write, and am hoping there is some wild command I can use in vim to make this simpler. From a file that is a list of fields, like the excerpt, for example: orderdetail.ccntyfips orderdetail.citemord orderdetail.coffdetid I want to go to this: ... (2 Replies)
Discussion started by: c444l
2 Replies
Login or Register to Ask a Question