DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Line to clip  (Read 7,237 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Line to clip
« on: December 02, 2012, 01:54 PM »
I need a little script for :

1) I have a txt file. by example :

This is the first line
This is the second line
http://www.donationcoder.com (this is the third line)
projects and advice (4)
......

2) I would like a script to convert in clips to the clipboard every line.

3) I have a txt file or similar, by example :

*
This is the first line
www.codingsnacks.tk
*
This is the second line
Post new requests here
*
This is the third line
http://www.donationcoder.com
*
projects and advive (4)

..........................
The goal is copy to the clipboard all the chain under the *
So I would like a script to read a txt file or similar and copy the lines or phrases under * to the clipboard.


4) Note : What I try to do later with this is not now the purpose. But the aim is inmediately I have one line or phrase in the clipboard execute another script to add as a register to a database.

Best Regards

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • Participated in NANY Challenge Once
Re: Line to clip
« Reply #1 on: April 10, 2013, 05:06 PM »
Hey Contro,

Not sure if you still needed this or not (since it's dated Dec 2012) so I'll kill two birds with one proverbial stone.

1.) My first post on the forums and hey to everyone!  "Hey" o/
2.) To address your needs

Code: (autohotkey)
;FileDelete, output.txt  ;deletes the output file -- uncomment along with FileAppend below if you so chose
FileRead, Contents, %A_ScriptDir%\clip.txt  ;place your text file with *'s in this directory & change name from clip.txt to anything
	if not ErrorLevel
	{
		set_f=0
		loop, parse, Contents, `n, `r
		{
			if (set_f=="1")
			{
				;FileAppend, %A_LoopField%`n, output.txt  ;uncomment this line to create an output file
				msg_output .= A_LoopField . "`n" 
				set_f=0
			}
			
			if (A_LoopField=="*")
				set_f=1
		}
	}
clipboard := msg_output  ;sets lines after * equal  to clipboard
msgbox % clipboard
exitapp

Hope this helps!
~BigVent
« Last Edit: April 10, 2013, 06:20 PM by BigVent »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Line to clip
« Reply #2 on: April 10, 2013, 07:50 PM »
;D

Welcomeeeeeee !!!!!!!!!!!

I try and comment.

Best Regards
:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Line to clip
« Reply #3 on: April 28, 2013, 12:57 AM »
Is not what i need. I see only a window.

:-[

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • Participated in NANY Challenge Once
Re: Line to clip
« Reply #4 on: April 28, 2013, 01:37 AM »
Save the quote below as "clip.txt" in the same folder as your ahk or exe.

It works here on three different OS's.  Can anyone else confirm?

Quote
*
This is the first line
www.codingsnacks.tk
*
This is the second line
Post new requests here
*
This is the third line
http://www.donationcoder.com


~BigVent
~BigVent

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Line to clip
« Reply #5 on: April 28, 2013, 07:06 PM »
I'll try and comment.
Best Regards
:-*

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • Participated in NANY Challenge Once
Re: Line to clip
« Reply #6 on: April 29, 2013, 06:11 PM »
To verify the code above works correctly:


Code: (autohotkey)
var =
(
*
This is the first line
www.codingsnacks.tk
*
This is the second line
Post new requests here
*
This is the third line
http://www.donationcoder.com
*
4th line in file
blah blah
more junk
*
5th line in file
blah blah more
junk
junk
)

set_f=0
loop, parse, var, `n, `r
{
	if (set_f=="1")
	{
		msg_output .= A_LoopField . "`n"
		set_f=0
	}
	if (A_LoopField=="*")  ;if line equals * per request... the next line is obtained -- append to variable
		set_f=1
}
msgbox % msg_output
   exitapp


Enjoy!

~BigVent
~BigVent

Original address: https://www.donationcoder.com/forum/index.php?topic=33119.0