Results 1 to 4 of 4

Thread: Sed Multiple Files insert apostrophe

  1. #1
    Join Date
    Jan 2014
    Beans
    2

    Question Sed Multiple Files insert apostrophe

    Hello all

    I have this current sh code
    Code:
    DELETE=`$MEGASYNC --username $USER --password $PASSWORD --dryrun  --reload --download --local $LOCALDIR --remote $REMOTEDIR | sed 's/F  '$SEDLOCALDIR'/'$SEDREMOTEDIR'/g'`
    an example of output of $DELETE is
    Code:
    /Root/W/my file 1.txt /Root/W/my file 2.txt /Root/W/my file 3.txt
    but i need
    Code:
    "/Root/W/my file 1.txt" "/Root/W/my file 2.txt" "/Root/W/my file 3.txt"
    what is the correct sed syntax for get the apostrophe?
    Thanks so much
    Last edited by RIK312; January 8th, 2014 at 01:20 AM.

  2. #2
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    3,095

    Re: Sed Multiple Files insert apostrophe

    Escape the quote (") char using a backlash (\)
    Example replacing all the 't' chars in a string with '"' chars:
    Code:
    $ echo example string | sed 's/t/\"/g'
    example s"ring

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Sed Multiple Files insert apostrophe

    Welcome to the forums!

    Please check out:
    http://mywiki.wooledge.org/Arguments
    and BashFAQ 020 (link in my signature).

    You didn't post the actual command which you use. Does it have an option to print null terminated list of file names?
    Last edited by sisco311; January 7th, 2014 at 10:52 PM.

  4. #4
    Join Date
    Jan 2014
    Beans
    2

    Re: Sed Multiple Files insert apostrophe

    Finally I have fixed the code from myself Anyone need the correct code is

    Code:
    #!/bin/sh
    USER="###"
    PASSWORD="###"
    MEGASYNC='/usr/local/bin/megasync'
    MEGARM='/usr/local/bin/megarm'
    LOCALDIR="/local/dir"
    REMOTEDIR="/Root/Dir"
    SEDLOCALDIR="\/local\/dir"
    SEDREMOTEDIR="\/Root\/Dir"
    BACKUP_TIME=`date +%c`
    LOG="/usr/local/bin/Mega - "`date +%d" "%m" "%y`".txt"
    DELETE=`$MEGASYNC --username $USER --password $PASSWORD --dryrun --reload --download --local $LOCALDIR --remote $REMOTEDIR | sed 's/F '$SEDLOCALDIR'/'$SEDREMOTEDIR'/g'`
    echo "$DELETE" | while read line ; do
    if [ ! -z "$line" ] ; then
    $MEGARM --username $USER --password $PASSWORD "$line"
    echo "[$BACKUP_TIME] File Removed "$line"" >> $LOG
    fi
    done
    $MEGASYNC --username $USER --password $PASSWORD --no-progress --local $LOCALDIR --remote $REMOTEDIR >> $LOG
    echo "[$BACKUP_TIME] Synchronization to MEGA Done!" >> $LOG
    Thanks all for the help! Have a nice day
    Last edited by RIK312; January 8th, 2014 at 01:19 AM. Reason: SOLVED

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •