First, you should confirm that the blank lines are actually blank, i.e. do not contain any invisible characters such as tab or space. Most decent text editors offer a ‘show invisibles’ feature but alas, textedit does not. SubEthaEdit is a good and free example, and BBEdit offers a free version which is very good.
You can check some example test in Script Editor though. Select the last character of the preceding paragraph through to the first character of the subsequent paragraph and copy to the clipboard. In a new script, set that text to a variable. Then, get the ‘id’ for the selected characters. For example, the text below consists of the following text: period, linefeed, space, space, tab, linefeed, letter A.
set ab to ".
A"
id of ab
[format]–> {46, 10, 32, 32, 9, 10, 65}[/format]
You can see that the ‘32’ characters are the spaces, the ‘9’ marks the tab. So if you used sed to delete blank lines, it would not consider this to be blank and would skip it.
Furthermore, if you add the line ‘characters of ab’ then it will return the characters as a list, like so.
[format]–> {“.”, "
", " ", " ", " ", "
", “A”}[/format]
So it would be worth confirming whether that is the case for your text file.
Now, as to deleting blank lines, unfortunately, you don’t include your sed command so who knows what you were doing, but in general, this command would delete any blank lines in a given file. What it does is find lines that have a beginning (^) and an end ($) but nothing in between and then deletes each one. Obviously, in the example above, it would not detect any.
sed -E '/^$/ d' < file
You can have it include tabs and spaces however, like this. The ‘[[:blank:]]’ is a character class that contains the tab and space characters, so this looks for lines that have either nothing or only tabs and spaces and then deletes them.
sed -E '/^[[:blank:]]*$/ d' <file
And to follow through for our above example,
echo ".
A" | sed -E '/^[[:blank:]]*$/ d'
results in:
.
A
So, to wrap that up in an applescript,
-- sed -E '/^[[:blank:]]*$/ d'
set xy to do shell script "echo \"" & ab & "\"" & " | sed -E '/^[[:blank:]]*$/ d' "
… will run these shell commands:
[format]"echo ".
A" | sed -E ‘/^[[:blank:]]*$/ d’ "[/format]
… and result in this:
[format]“.
A”[/format]