BookmarkSubscribe
Choose Language Hide Translation Bar
xenon2090
Community Trekker

Write specific lines from one file to another

I have a large txt file. I want to find the lines starting with a specific string (e.g. "student name=") and copy the entire of such lines into another file.

 

How can I do it with JMP scripting?

 

If it is not straightforward with JMP, is there a simple method by excel or other tools?

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Write specific lines from one file to another

See if you can adapt this illustrative script to suit your situation:

 

Names Default to Here( 1 );

text = Load Text File( "YourText1.txt" );

line = Words( text, "\!n" );

text = "";

For( i = 1, i <= N Items( line ), i++,
	If( Contains( line[i], "student name =" ),
		text ||= line[i] || "\!n";
	);
);

Save Text File( "YourText2.txt", text );
Learn it once, use it forever!
2 REPLIES 2

Re: Write specific lines from one file to another

See if you can adapt this illustrative script to suit your situation:

 

Names Default to Here( 1 );

text = Load Text File( "YourText1.txt" );

line = Words( text, "\!n" );

text = "";

For( i = 1, i <= N Items( line ), i++,
	If( Contains( line[i], "student name =" ),
		text ||= line[i] || "\!n";
	);
);

Save Text File( "YourText2.txt", text );
Learn it once, use it forever!
Highlighted
txnelson
Super User

Re: Write specific lines from one file to another

@markbailey  responded with a scripting solution.  I am thinking that what you are really trying to do, may be to create a new JMP data table from an existing data table, based upon finding all rows in the data table that contain the string "student name=".

This can be done very easily using the interactive tools within JMP.

1. Open the data table you are interested in

2. Right click on the column header over the rowstate column(row number column) and select 

     Row Selection==>Select Where

select1.PNG

3. Select the column you want to query against, and then choose "Contains" and then type in the value, "student name="

select2.PNG

4. The result of this operation, will select all rows that has the phrase "student name=".

select3.PNG

5. You can then go to 

     Tables==>Subset

and subset all rows that have been selected

select4.PNG

Jim