Q: use sed to delete a record in applescript
I'm trying to use sed in an Applescript shell script to delete a specific record number. When I enter a number for the record number it works perfectly but I would like to use a calculated variable. I have tried all sorts of escape characters and quoted forms but cannot get it to work, any guidance would be gratefully received.
set filePath to quoted form of "/Users/Ours/Documents/Cats Protection/Cats/CP Cats copy.csv"
set recNo to 3
do shell script "sed -i \"\" 'recNo d' " & filePath -- delete line number
iMac, OS X El Capitan (10.11.2)
Posted on Aug 12, 2016 3:40 AM
Hello
Try something like the following.
set f to "/path/to/file.csv" set n to 3 do shell script "sed -i '' -e '" & n & "d' " & f's quoted form
The point is you need to build the complete command line statement in AppleScript and pass it to do shell script command, for AppleScript has no facility of variable interpolation in string literal.
Good luck,
H
Posted on Aug 12, 2016 11:03 AM