LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 09-10-2017, 12:24 PM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Rep: Reputation: 15
\ in variable vanishes while in sed append feature


I want to append below find command in a file under a line matching a string.

command:
Quote:
find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;
File:
Quote:
$ cat disk.sh
for id abc
I am taking a command in variable and then using sed to add command via variable under a line below match.

Quote:
$ COMM=`echo "find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;"`

$ sed -i "/for id abc/a ${COMM}" disk.sh
However in output \ dissappears.

Quote:
$ cat disk.sh
for id abc
find /path/to/dir -type f ( -name '*.gz' -o -name '*.log' ) -mtime + ${days} -exec rm -fr {} ;
But variable seem to have captured the whole command perfectly.

Quote:
$ echo ${COMM}
find /path/to/dir -type f \( -name '*.gz' -o -name '*.log' \) -mtime + ${days} -exec rm -fr {} \;
 
Old 09-10-2017, 02:10 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
duplicate of
https://www.linuxquestions.org/quest...re-4175613554/
 
2 members found this post helpful.
Old 09-10-2017, 03:22 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,294
Blog Entries: 24

Rep: Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254Reputation: 4254
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

As your other thread has received replies this one will be closed. Please continue the discussion here.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] append text with sed tripialos Linux - Newbie 6 11-12-2014 04:33 AM
how can i append the text after pattern match using variable in sed ravikushal Linux - Newbie 18 07-23-2013 08:56 AM
[SOLVED] sed append string in variable to last line of file. SilversleevesX Linux - Newbie 7 11-27-2011 11:13 PM
using sed to append a variable after a certain line jadeddog Programming 6 11-05-2008 12:49 AM
sed script to append variable text gmartin Linux - General 4 12-27-2006 04:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration