Deleting first paragraph in string

I have a text file that looks like this:

4xpe-b9wv
4c9b-wzh8
qs2l-cgq2
g4lq-xb6c
3cs6-ew9x
dj4u-3wyq
s9cd-x42z
p2hc-jpw6
7hye-yddv
xcu9-bhs8
jpwz-wjc2
(continues about another 40 lines)

I want to just to grab the FIRST line (4xpe-b9wv), save it in a variable, delete it from the text file, then resave the text file with out it, like this:

4c9b-wzh8
qs2l-cgq2
g4lq-xb6c
3cs6-ew9x
dj4u-3wyq
s9cd-x42z
p2hc-jpw6
7hye-yddv
xcu9-bhs8
jpwz-wjc2

Any ideas?

Elijah

This is the basic idea:

-- 'myfile' should be an alias to the text file.

set fRef to (open for access myFile with write permission)
try
	set theText to (read fRef as string) -- assuming the text isn't Unicode.
	
	set firstLine to paragraph 1 of theText
	if ((count theText's paragraphs) > 1) then
		set restOfText to text from paragraph 2 to -1 of theText
	else
		set restOfText to ""
	end if
	
	set eof fRef to 0 -- Empty the file before writing different data to it.
	write restOfText as string to fRef
on error msg
	display dialog msg buttons {"OK"} default button 1
end try
close access fRef

I noticed that you said only if the text file isn’t unicode. What should it be?

I’m not sure what you’re asking.

You have to tell the ‘read’ command how to interpret the data in the file (ie. what kind of data the file contains) with the ‘as’ parameter. This means you have to know in advance what kind of data they are. With text, the possibilities which ‘read’ understands are:

as string (or as text) : 1-byte-per-character “ASCII” text. This is actually the default, so you could omit it.
as Unicode text : UTF-16 Unicode text. (2 bytes per character, but more if needed. Big-endian unless the file begins with a little-endian BOM.)
as «class utf8» : UTF-8 Unicode text. (1 byte per character, but more if needed.)

I believe most “text” files you’re likely to encounter are either “ASCII” text or UTF-8.

In AppleScript, these type distinctions are only heeded by the File Read/Write commands and only apply to the data in the file. All ‘text’ within the language itself (including the result of a ‘read’) is UTF-16 Unicode text, and ‘text’, ‘string’, and ‘Unicode text’ all mean the same thing.