SED command works in terminal, but not Applescript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED command works in terminal, but not Applescript
# 1  
Old 03-04-2012
Question SED command works in terminal, but not Applescript

The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.)
(new to site. sorry.)
I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets.
I ran the following code from Terminal and it does exactly what I want it to do.
However, when I attempt to use this code inside an Applescript, it errors at the square brackets.
I am looking for syntax that will resolve this.

Code:
$ sed 's/\[.*\]//' File1.xml  > File1.xml.tmp


Last edited by Phillip Acosta; 03-05-2012 at 04:41 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 06-19-2012
Hello,
Your issue is in the backslash "\"
corrected:

do shell script "sed 's/\\[.*\\]//' File1.xml > File1.xml.tmp"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

2. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

3. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

4. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfile This code... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

5. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

6. OS X (Apple)

[Solved] Running shell code in AppleScript without Terminal

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete. Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time. To simplify my question, this is what I want to achieve.... (9 Replies)
Discussion started by: ShadowofLight
9 Replies

7. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

8. OS X (Apple)

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
Discussion started by: JFraser1
2 Replies

9. Shell Programming and Scripting

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
Discussion started by: JFraser1
3 Replies

10. Shell Programming and Scripting

Terminal vs. Applescript

I am running Mac OS X (10.5). I run the following script successfully in terminal in order to split an mp3 file into 3 smaller mp3 files... split -b 8667k -a1 Monday.mp3 Levin-Hour_; ls Lev* | sed "s/.*/mv '&' '&.mp3'/g" | zsh However, when I run a similar script within the Applescript editor... (2 Replies)
Discussion started by: tgaleza
2 Replies
Login or Register to Ask a Question