Login  Register

Re: save measurements without 1st row labels

Posted by Michael Schmid on Oct 29, 2008; 10:39am
URL: http://imagej.273.s1.nabble.com/save-measurements-without-1st-row-labels-tp3694643p3694645.html

Hi Justin,

you can run copy&paste from a macro:

String.copyResults();
myResultsString=String.paste();
File.saveString(myResultsString, myPath);

-------------
Alternative: call awk via the "exec" command from a macro, e.g. on  
unix-type systems:

exec("/bin/sh", "-c", "awk 'NR>1' <"+myFilePathAndName+"  
 >"+myFilePathAndName+"_converted");

The first two arguments are needed because file redirection is  
handled by the shell.
For more "exec examples", see
   http://rsb.info.nih.gov/ij/macros/ExecExamples.txt

-------------
Alternatives on operating-system level:

A loop over files - here for all .txt files on Unix-type systems

!#/bin/sh
for file in `ls *.txt`
do
   awk 'NR>1' <$file >converted_$file
done

The line "!#/bin/sh" should be the first line of the file.

-------------
A loop over files in DOS is probably something like this:

set AWK=%ProgramFiles%\GnuWin32\bin\gawk.exe
for /D %%g in (*.txt) do %AWK% "NR^>1" "%%g" >"converted_%%g"

Notes on the DOS version:
- The first line sets the location of the awk program.
- Note that the ">" character in the awk command has to be escaped by  
a caret; otherwise it would be a redirect into a file named "1".
- I am not sure about the quotes around "NR^>1" etc. - I don't have a  
Windows machine here to try it.
- When running it on the command line, not in a batch file, you have  
to replace %%g by %g.


Hope this helps,

Michael
________________________________________________________________

On 28 Oct 2008, at 21:15, Justin Walker wrote:


> Unfortunately, I need something that will work in batch mode - I  
> have hundreds of images, each of which gets processed and generates  
> it's own text file, so the clipboard is out.
>
> Do you know how I could implement the awk command in a batch mode?
>
> - Justin
>
> Michael Schmid wrote:
>
>> Hi Justin,
>>
>> it is easy when copying the results to the clipboard:
>> deselect Edit>Options/Input/Output Options>Copy Column Headers
>>
>> Files - on linux or MacOS (terminal), this deletes the first line:
>> (gnu awk is also available for Windows, you can run it in a DOS  
>> window)
>>   awk 'NR>1' <inputFile >outputFile
>>
>> Michael
>> ______________________________________________________________
>>
>> On 28 Oct 2008, at 20:43, Justin Walker wrote:
>>
>>
>>> Does anyone know if there is a way to save the contents of the  
>>> results box without the labels in the first line of the text  
>>> file?  I'm trying to write code to import those data files  
>>> directly and do processing on them, but I'm being hung up by the  
>>> row of labels, and deleting them is a pain.
>>>
>>> Alternatively, does anyone know of a simple way to delete the  
>>> first line of a whole bunch of text files?
>>>
>>> Thanks
>>>
>>> -Justin Walker
>>> University of Maryland
>>>