Trying To fill textarea with some data - csv

i've been trying to make this script work , but i just can't figure it out ! I would appreciate if somebody could help me.
So I'll start explaining:
-I have a list of email addresses in a text file , i know imacros only supports csv so what i do is :
At the end of each line i replace "\n" with a "," and save it as a csv.
Then i try to paste 25 email addresses.
It works , i get the email addresses , but now im stuck here trying to paste the next 25 addresses.
Here is what i made :
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
'TAB CLOSEALLOTHERS
SET !DATASOURCE ppl.csv
'SET !LOOP 1
'SET !DATASOURCE_LINE {{!LOOP}}
FRAME F=3
TAG POS=1 TYPE=TEXTAREA FORM=ID:addmember ATTR=ID:add-members-textarea CONTENT={{!COL1}}<SP>{{!COL2}}<SP>{{!COL3}}<SP>{{!COL4}}<SP>{{!COL5}}<SP>{{!COL6}}<SP>{{!COL7}}<SP>{{!COL8}}<SP>{{!COL9}}<SP>{{!COL10}}<SP>{{!COL11}}<SP>{{!COL12}}<SP>{{!COL13}}<SP>{{!COL14}}<SP>{{!COL15}}<SP>{{!COL16}}<SP>{{!COL17}}<SP>{{!COL18}}<SP>{{!COL19}}<SP>{{!COL20}}<SP>{{!COL21}}<SP>{{!COL22}}<SP>{{!COL23}}<SP>{{!COL24}}<SP>{{!COL25}}
'TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:addmember ATTR=ID:add-members-add-button
So the whole idea is to get 25 email addresses , add them to a database , then start from number 26 and add other 25 until there is no more.

//I have used javascript code with imcaros. May be this helps.
macro += "TAB T=1" + "\\n";
macro += "SET !DATASOURCE 39.csv" + "\\n";
macro += "SET !DATASOURCE_LINE {{i}}" + "\\n";
macro += "ADD !EXTRACT {{!COL1}}"+ "\\n";
//here u can stop the macro.js file and start at any value for your use case
for(var i=1;i<50;i++){
iimSet("i",i);
iimPlay(macro);
}

Related

remove comma in jsonpath template using bash

I have a JSON path template query.
oc get event jsonpath='{range .items[*]},{#.name}{","}{#.message}{","}{#.evenname}'{"\n"}{end}'> /tmp/test.csv
i'm redirecting it to csv.
name1,message of event one,eventname1
name2,message of,event,two,eventname2
name3,message of event three,eventname3
name4,message of, event four,eventname4
getting comma in a message from above output , i want to replace the comma with space for the second column(message) in the bash script.
Anyone has any thoughts on how can achieve this.
Expected result
name1,message of event one,eventname1
name2,message of event two,eventname2
name3,message of event three,eventname3
name4,message of event four,eventname4
Assuming you can change the field delimiter to a character known to not exist in the data (eg, |), you would now be generating:
name1|message of event one|eventname1
name2|message of,event,two|eventname2
name3|message of event three|eventname3
name4|message of, event four|eventname4
From here we can use sed to a) remove/replace , with <space> and then b) replace | with ,:
$ sed 's/[ ]*,[ ]*/,/g;s/,/ /g;s/|/,/g'
NOTE: the s/[ ]*,[ ]*/g is needed to address the additional requirement of stripping out repeating spaces (as would occur in line #4 if we replace , with <space>)
When applied to the data this generates:
name1,message of event one,eventname1
name2,message of event two,eventname2
name3,message of event three,eventname3
name4,message of event four,eventname4
Another option using awk (for OP's current data using the , as the field delimiter):
awk -F',' ' # input field delimiter = ","
{ x=$1"," # start new string as field #1 + ","
sep="" # initial separator = "" for fields 2 to (NF-1)
for (i=2;i<NF;i++) { # loop through fields 2 to (NF-1)
gsub(/^[ ]+|[ ]+$/,"",$i) # trim leading/trailing spaces
x=x sep $i # append current field to x along with sep
sep=" " # use " " as separator for rest of fields
}
printf "%s,%s\n", x, $NF # print "x" plus "," plus the last field (NF)
}'
When applied to the data this generates:
name1,message of event one,eventname1
name2,message of event two,eventname2
name3,message of event three,eventname3
name4,message of event four,eventname4

Export to CSV using SAVE TRANSLATE but empty values are exported as a single space

I have a dataset in SPSS, see example dataset below. This is just an example, the real one is provided by a separate external process and has more columns and rows. The empty values are set as " " in the example but this is also how empty values are provided in SPSS, it's treated internally as null/empty/missing values.
data list list/FieldNam(a20) FormName(a20) FieldType(a20) Choices(a50) Required(F1) Identifier(a1) Minimum(f8) Maximum(f8).
begin data
"Field 1" "Form abc" "text" " " 1 "y" " " " "
"Field 2" "Form abc" "datetime" " " 1 "y" " " " "
"Field 3" "Form xyz" "radio" "0=never | 1=sometimes | 2=often | 3=always" " " " " " " " "
"Field 4" "Form xyz" "text" " " " " " " "1" "100"
"Field 5" "Form xyz" "radio" "0=no | 1=yes" " " " " " " " "
end data.
Then I use the following syntax to save it as a CSV text file.
SAVE TRANSLATE
/TYPE = CSV
/FIELDNAMES
/TEXTOPTIONS DELIMITER=',' QUALIFIER='"'
/OUTFILE = 'C:\Temp\my_csv_file.csv'
/ENCODING='Windows-1252'
/REPLACE.
And the resulting CSV file contains the following, with single spaces for the empty values
FieldNam,FormName,FieldType,Choices,Required,Identifier,Minimum,Maximum
Field 1,Form abc,text, ,1,y, ,
Field 2,Form abc,datetime, ,1,y, ,
Field 3,Form xyz,radio,0=never | 1=sometimes | 2=often | 3=always, , , ,
Field 4,Form xyz,text, , , ,1,100
Field 5,Form xyz,radio,0=no | 1=yes, , , ,
However, I would like the empty values to just be empty, like so:
FieldNam,FormName,FieldType,Choices,Required,Identifier,Minimum,Maximum
Field 1,Form abc,text,,1,y,,
Field 2,Form abc,datetime,,1,y,,
Field 3,Form xyz,radio,0=never | 1=sometimes | 2=often | 3=always,,,,
Field 4,Form xyz,text,,,,1,100
Field 5,Form xyz,radio,0=no | 1=yes,,,,
So my question is, is it possible to export the SPSS dataset like this?
The exported csv file will be used as input for another system, and it cannot handle the , , empty values. I know I can open it in Notepad and just do search-and-replace after the fact. But I want to automate it as much as possible because the export will be used more often, so this would save a lot of work.
Information from this page suggests one can invoke a script: https://www.ibm.com/docs/en/spss-statistics/23.0.0?topic=reference-script
SCRIPT
SCRIPT runs a script to customize the program or automate
regularly performed tasks. You can run a Basic script or a Python
script.
SCRIPT 'filename' [(quoted string)]
This command takes effect immediately. It does not read the active
dataset or execute pending transformations. See the topic Command
Order for more information.
Release History
Release 16.0
Scripts run from the SCRIPT command now run synchronously with the
command syntax stream.
Release 17.0
Ability to run Python scripts introduced.
Example Python script to invoke after each export for release 17.0 or higher:
import fileinput
import os
filename = 'C:\Temp\my_csv_file.csv'
postfix = '.bak'
with fileinput.FileInput(filename, inplace=True, backup=postfix) as file:
for line in file:
print(line.replace(', ', ',').replace(' ,', ','), end='')
try:
os.remove(filename + postfix)
except FileNotFoundError as e:
pass
The script performs a simple search and replace. I've included code to automatically remove the temporary backup file even though the Python manual states it automatically removes the file. For me it consistently does not at the moment (thus the manual removing of the file). But you may remove that specific code if it works without it for you.
Of course you could also use Python's csv module and iterate the rows and write it back to another csv, etc. See the documentation for that one here: https://docs.python.org/3/library/csv.html

Batch File for convert txt to CSV removes spaces and commas convert to columns

I am new in batch file programs.
I have lots of text (.txt) files to convert to CSV. if using manual method with (copy-paste to excel) remove space or comma and convert to column it will take a lot of time.
I have an idea to create a batch file and put it in the same folder where the text (.txt file) will be converted to CSV when the batch file is run, it will automatically convert the text to CSV and create the CSV file.
The text file format is shown below
As text:
ADINA: AUI version 9.3.1, 22 November 2017: *** NO HEADING DEFINED ***
Licensed from ADINA R&D, Inc.
Finite element program ADINA, response range type load-step:
Listing for zone EG1:
POINT NODAL_FORCE-R
Time 1.40000E+01
Element 101100 of element group 1
Local node 1 -2.96954E+03
Local node 2 2.96954E+03
Element 101200 of element group 1
Local node 1 1.31964E+04
Local node 2 -1.31964E+04
Element 101300 of element group 1
Local node 1 1.38607E+04
Local node 2 -1.38607E+04
Element 101400 of element group 1
Local node 1 -3.57060E+03
Local node 2 3.57060E+03
Element 102100 of element group 1
Local node 1 2.22511E+04
besides that, I want to delete text in the red box. because I don't use it.
The CSV file I want to create is shown below
Folder structure
Is there any solution for this batch file code?
Really appreciate your help. Thanks all!
I think this might do what you want:
#echo off
if "%1" == "" goto FindFiles
:ProcessFile
for /F "tokens=1,2,3,4,5,6" %%A in (%1) do (
if "%%A" == "Time" echo %%A,%%B
if "%%A" == "Local" echo %%A,%%B,%%C,%%D
if "%%A" == "Element" echo.
if "%%A" == "Element" echo %%A,%%B,%%C,%%D,%%E,%%F
if "%%A" == "Element" echo.
)
goto Exit
:FindFiles
for %%I in (*.txt) do call %0 %%I > %%~nI.csv
goto Exit
:Exit
When double-clicked it runs itself once for each *.txt file in the current folder.
Each file is processed by only saving lines starting with Time, Local or Element (adding blank lines when needed).
Each line that is saved has each space-separated value saved with commas between instead.
Here's a basic example for you to work through as part of your learning experience. The answer is designed to work only with the posted text file content you have provided. I will not be explaining anything within it, or changing anything due to subsequent changes to your originally posted task, (as you have not attempted anything yourself).
#If Exist "force.txt" ((For /F "Skip=9 Tokens=1-7" %%G In (
'%__AppDir__%find.exe /N /V "" ^< "force.txt"'
) Do #If Not "%%M" == "" (Echo %%H,%%I,%%J,%%K,%%L,%%M
) Else If Not "%%L" == "" (Echo %%H,%%I,%%J,%%K,%%L
) Else If Not "%%K" == "" (Echo %%H,%%I,%%J.%%K
) Else If Not "%%J" == "" (Echo %%H,%%I,%%J
) Else If Not "%%I" == "" (Echo %%H,%%I
) Else If Not "%%H" == "" (Echo %%H) Else Echo=) > "force.csv")
Once inside your spreadsheet you will still need to incorporate your required cell alignment and formatting changes, if you want it to match your posted image.

Writing onto a CSV column on applescript

So I'm creating a script in AppleScript that needs to write onto a column in a CSV. I've already read from the CSV and I have code on how to write onto a CSV but it doesn't write at all. I want to write on column 22. At the moment, I can read from that column but I'm not sure how to edit the column. Or is there a way to edit a certain box in excel like A3 to say this "Yes". I've attached my code below.
set theFile to (choose file)
set f to read theFile
-- break the file into paragraphs (c.f. rows)
repeat with row in (paragraphs of f)
-- parse the row into comma-delimited fields
set fields to parseCSV(row as text)
-- now you have your data:
set verifyAccountStatus to item 22 of fields
set theResult to writeTo(verifyAccountStatus, "Yes", text, true)
end repeat
on parseCSV(theText)
set {od, my text item delimiters} to {my text item delimiters, ","}
set parsedText to text items of theText
set my text item delimiters to od
return parsedText
end parseCSV
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
EDIT:
For some reason it isn't working when I run this.
set theFile to (choose file)
set openFile to open for access theFile with write permission
do shell script "awk -F, '$1 ~ /Line 7/{$22=\"hello\"} 1' openFile"
close access openFile
It says it can't open file openFile
Maybe consider doing this using awk which is built-in to OS X anyway. Say your file is called file.csv and it is comma-separated and looks like this:
Line 0,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,16
Line 1,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,44
Line 2,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,93
Line 3,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
Line 4,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,19
Line 5,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,77
Line 6,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,30
Line 7,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,30
Line 8,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,1
Line 9,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
If you run this awk script in the Terminal, it will change all the field22 entries to "Hello"
awk -F, '{$22="hello"}1' OFS=, file.csv
and give you this:
Line 0,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,16
Line 1,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,44
Line 2,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,93
Line 3,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,96
Line 4,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,19
Line 5,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,77
Line 6,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,30
Line 7,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,30
Line 8,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,1
Line 9,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,hello,f23,f24,96
If you want that in a new file, just redirect the output like this:
awk -F, '{$22="hello"}1' OFS=, file.csv > newfile.csv
You can call this from Applescript using:
do shell script "awk -F, '{$22=\"hello\"} 1' file.csv > newFile.csv"
If you want the user to choose a file from a dialog window, then your filename will be in an Applescript variable - in your example it is called theFile. You will then need to convert this to a filename that the shell and awk understand, and quote it and pass it to the shell something like this:
do shell script "awk -F, '{$22=\"hello\"} 1' & quoted form of POSIX path of theFile & " > /tmp/a"
If you only want to change field 22 on lines that contain "77" anywhere on them, do this:
awk -F, '/77/ {$22="hello"} 1' file.csv
Line 0,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,16
Line 1,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,44
Line 2,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,93
Line 3,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
Line 4,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,19
Line 5 field2 field3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 hello f23 f24 77
Line 6,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,30
Line 7,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,30
Line 8,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,1
Line 9,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
If you only want to change field22 on lines where field 1 matches "Line 7", you can do this:
awk -F, '$1 ~ /Line 7/ {$22="hello"} 1' file.csv
Line 0,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,16
Line 1,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,44
Line 2,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,93
Line 3,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
Line 4,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,19
Line 5,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,77
Line 6,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,30
Line 7 field2 field3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 hello f23 f24 30
Line 8,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,1
Line 9,field2,field3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,f18,f19,f20,f21,f22,f23,f24,96
Note:
The -F, just tells awk that input fields are separated by commas. The OFS=, tells awk to separate output fields by commas.

Extracting + Saving to CSV with Header?

Is it possible to, when I save the extracted values in a csv file, add a Header or something in the first row of each column, so it's easier to know what the values refer to?
Thanks!
before beginning to extract with your main macro prepare your file with another one:
macro1 = "CODE:";
macro1 += "SET !EXTRACT First<SP>Header,<SP>Second<SP>Header" + "\n";
macro1 += "SAVEAS TYPE=EXTRACT FOLDER=U:\imacros FILE=test.csv" + "\n";
ret = iimPlay(macro1);
I just came upon this page looking for an answer to the same question. I found that I was able to get symbiotech's answer to work if I separated the headers with [EXTRACT] rather than with commas.
macro1 = "CODE:";
macro1 += "SET !EXTRACT First<SP>Header[EXTRACT]Second<SP>Header" + "\n";
macro1 += "SAVEAS TYPE=EXTRACT FOLDER=U:\imacros FILE=test.csv" + "\n";
ret = iimPlay(macro1);