• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Q: echo | sed ; can't replace range of lines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q: echo | sed ; can't replace range of lines


  • Subject: Re: Q: echo | sed ; can't replace range of lines
  • From: Gnarlodious <email@hidden>
  • Date: Mon, 17 May 2004 20:00:33 -0600

That doesn't do a thing for me, does it work for you?

set someLines to "1
2
3
4
5
6"

-- > variable string 1\r2\r3\r4\r5\r6\r
'1
2
3
4
5
6'


set someLines to the quoted form of "1
2
3
4
5
6"

-- > variable string '1\r2\r3\r4\r5\r6\r'

This doesn't even work:


set unixText to do shell script "echo " & someLines & " | tr -s '\\r' '\\n'
" without altering line endings

do shell script "echo " & unixText & " | sed '/2/,/5/d'"


Maybe this functionality is broken in Script debugger?

--
Gnarlie's virtual Tour de Santa Fe
http://www.Gnarlodious.com/SantaFe/Tour.php





Entity Graff spoke thus:

> You need to quote the string you are passing to the shell because of
> the return characters. The return characters cause the command to be:
> ----
> echo 1<return>
> 2<return>
> 3<return>
> 4<return>
> 5<return>
> 6 | sed 's/2/8/'
> ----
>
> So the shell misinterprets your command. Here is a corrected version
> of the script:
> ----
> set someLines to quoted form of "1
> 2
> 3
> 4
> 5
> 6"
>
> do shell script "echo " & someLines & " | sed 's/2/8/'"
> -->"1
> -->8
> -->3
> -->4
> -->5
> -->6"
>
> do shell script "echo " & someLines & " | sed '/2/,/5/d'"
> -->"1
> -->6"
> ----
>
> - Ken
>
> On May 17, 2004, at 6:38 PM, Gnarlodious wrote:
>
>> Why does the first command work but the 2nd doesn't?
>>
>> set someLines to "1
>> 2
>> 3
>> 4
>> 5
>> 6"
>>
>> set replaceLine to do shell script "echo " & someLines & " | sed
>> 's/2/8/'"
>>
>> set deleteRange to do shell script "echo " & someLines & " | sed
>> '/2/,/5/d'"
>>
>>
>> It operates on a text file just fine:
>>
>> do shell script "sed -e '/2/,/5/d' testFile"
>>
>> -- > 1
>> -- > 6
>>
>>
>> Am I doing something wrong?
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Q: echo | sed ; can't replace range of lines
      • From: Graff <email@hidden>
References: 
 >Re: Q: echo | sed ; can't replace range of lines (From: Graff <email@hidden>)

  • Prev by Date: Re: adding authentication...
  • Next by Date: problem to display Tibetan
  • Previous by thread: Re: Q: echo | sed ; can't replace range of lines
  • Next by thread: Re: Q: echo | sed ; can't replace range of lines
  • Index(es):
    • Date
    • Thread