Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 08-09-2012, 03:12 PM   #1
stash
Prospect
 
Join Date: Aug 2011
Posts: 2
Need help with script

Hey guys I have a list of serial numbers that start off with a "S" character that I need to remove with a script. The tricky thing is that I only need to remove the "S" that shows up second in the serial number. Does anyone have any ideas or a script that could help?

Thanks

Example:

Before script
SER-NO SC02H706NDJGR
SER-NO SC02H707PDJGR
SER-NO SC02H708YDJGR
SER-NO SC02H79TBDJGR

After script
SER-NO C02H706NDJGR
SER-NO C02H707PDJGR
SER-NO C02H708YDJGR
SER-NO C02H79TBDJGR
stash is offline   Reply With Quote
Old 08-09-2012, 04:49 PM   #2
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
Quote:
Originally Posted by stash
Hey guys I have a list of serial numbers that start off with a "S" character that I need to remove with a script. The tricky thing is that I only need to remove the "S" that shows up second in the serial number. Does anyone have any ideas or a script that could help?

Thanks

Example:

Before script
SER-NO SC02H706NDJGR
SER-NO SC02H707PDJGR
SER-NO SC02H708YDJGR
SER-NO SC02H79TBDJGR

After script
SER-NO C02H706NDJGR
SER-NO C02H707PDJGR
SER-NO C02H708YDJGR
SER-NO C02H79TBDJGR

set BeforeScript to {"SER-NO SC02H706NDJGR", "SER-NO SC02H706NDJGR", "SER-NO SC02H708YDJGR", "SER-NO SC02H79TBDJGR"}
set c to count BeforeScript
set AfterScript to {}

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "S"
tell BeforeScript
repeat with k from 1 to c
set tPart to text item 3 of item k
set end of AfterScript to "SER-NO " & tPart
end repeat
end tell
set AppleScript's text item delimiters to tid
--> {"SER-NO C02H706NDJGR", "SER-NO C02H706NDJGR", "SER-NO C02H708YDJGR", "SER-NO C02H79TBDJGR"}
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3

Last edited by NovaScotian; 08-09-2012 at 04:51 PM.
NovaScotian is offline   Reply With Quote
Old 08-13-2012, 03:52 PM   #3
sojourner
Major Leaguer
 
Join Date: Apr 2010
Posts: 324
Assuming you have a file containing those serial numbers you want to convert (and only those serial numbers you want to convert)...

Code:
set listSerialNums to paragraphs of (read (choose file))

set numFileIdNewSerialNums to open for access ((path to desktop folder as string) & "corrected serial numbers" & space & (random number from 1 to 1000) & ".txt") with write permission

repeat with textSerialNum in listSerialNums
	if textSerialNum ≠ "" then
		set textCorrectedSerialNum to text 2 thru -1 of (word 3 of textSerialNum)
		write (textCorrectedSerialNum & return) to numFileIdNewSerialNums as text
	end if
end repeat

close access numFileIdNewSerialNums
__________________
see a problem; solve a problem.
sojourner is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 05:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.