How to read data from csv file that has line breaks - imacros

I have example data in csv file
Some text
Text 2
Text 3
I want to output it with line break into text area, but getting error when trying to put it as it is.
it works only when i remove line breaks
iimPlayCode('ADD !EXTRACT {{!COL1}}\n');
var description = iimGetExtract(1);

Edit your csv file by adding double quotes:
"1. Some text2. Text 2 3. Text 3"
And run the code:
iimPlayCode('SET !DATASOURCE yourfile.txt\nADD !EXTRACT {{!COL1}}');
var description = iimGetExtract(1);

Related

iMacros - How to Extract the first 100 Characters from a `TAG CONTENT`?

I am using this code in iMacros to extract only the first 100 characters from TAG CONTENT and it's working in 80% of the cases, but sometimes iMacros displays an error message:
"TypeError: Cannot read properties of null (reading 'join'), line: 27"
(Line 27 in iMacros Code is where the code is executed.)
=> My question:
Is there another way to do this, another Regex code, or did I do something wrong with the script below?
TAG POS=1 TYPE=DIV ATTR=ID:title EXTRACT=TXT
SET titlu100 EVAL("var x=\"{{!EXTRACT}}\"; x=x.match(/^.{100}/).join(''); x;")
I am using (FCI):
iMacros for CR v10.1.1 'PE', CR v105.0.5195.102 (_x64), Win10_x64.
('CR' = 'Chrome' / 'PE' = 'Personal Edition')
Meanwhile I found another way to extract first 100 characters
SET titlu100 EVAL("\"{{!EXTRACT}}\".substr(0,100);")

Read multiple excel sheets on specific column and right them in one csv file using python

I have multiple sheets in one excel file like Sheet1, Sheet2, Sheet3,etc. Now I have to list all the particular column in one csv file. Both the sheets has one unique column "Attribute" and only those records should be listed in the csv file line by line. (First sheet's 'Attribute' values should be in 1st line and 2nd sheet's 'Attribute' values should be in 2nd line and etc.,)
If instances,
Sheet1:
Attribute,Order
P,1
Emp_ID,2
DOJ,3
Name,4
Sheet2:
Attribute,Order
C,1
Emp_ID,2
Exp,3
LWD,4
Expected result: (In some .csv file)
P,Emp_ID,DOJ,name
C,Emp_ID,Exp,LWD
Note: Line starting from P should be in first line and C should be in 2nd line and etc.,
Below is my code:
import pandas as pd
excel = 'E:\Python Utility\Inbound.xlsx'
K = 'E:\Python Utility\Headers_Files\All_Header.csv'
df = pd.read_excel(excel,sheet_name = None)
data = pd.DataFrame(df,columns=['Attribute']).T
print data
M = data.to_csv(K, encoding='utf-8',index=False,header=False)
print 'done'
Output show's as below:
Empty DataFrame Columns: [] Index: [Attribute] done
If I use sheet_name = 'sheet1' then DataFrame works good and data loaded as expected in csv file.
Thanks in advance

Csv file containing new line (multi line)

We are working on a project where are planning to generate multi line csv files and load to informatica via power exchange.
Our csv file will look like as below.
Field1, Field2
"Row 1 Cell 1 line 1
Row 1 Cell 1 line 2", "Row 1 Cell 2 Line 1
Row 1 Cell 2 line 2"
"Row 2 Cell 1 line 1
Row 2 Cell 1 line 2", "Row 2 Cell 2 Line 1
Row 2 Cell 2 Line 2"
Just wanted to check will power exchange understand this type of csv file?
Update: We tried loading a sample file to power exchange and it converted the new lines to space :-( Is there a way to retain then as new line and load to the data center as new line?
Yoc can use Informatica custom properties "MatchQuotesPastEndOfLine = Yes" in Session setting
CSV File: CSV file should be comma separated values, Multi line separation will not work.
PowerExchange: when you create powerexchange datamaps for the csv file, you can preview the data, how the data looking there? try to play with powerexchange setting while creating the datamaps and see if you can configure some properties.

How to parse/pull specific data out of a file with Python

I have an interesting issue I am trying to solve and I have taken a good stab at it but need a little help. I have a squishy file that contains some lua code. I am trying to read this file and build a file path out of it. However, depending on where this file was generated from, it may contain some information or it might miss some. Here is an example of the squishy file I need to parse.
Module "foo1"
Module "foo2"
Module "common.command" "common/command.lua"
Module "common.common" "common/common.lua"
Module "common.diagnostics" "common/diagnostics.lua"
Here is the code I have written to read the file and search for the lines containing Module. You will see that there are three different sections or columns to this file. If you look at line 3 you will have "Module" for column1, "common.command" for column2 and "common/command.lua" for column3.
Taking Column3 as an example... if there is data that exists in the 3rd column then I just need to strip the quotes off and grab the data in Column3. In this case it would be common/command.lua. If there is no data in Column3 then I need to get the data out of Column2 and replace the period (.) with a os.path.sep and then tack a .lua extension on the file. Again, using line 3 as an example I would need to pull out common.common and make it common/common.lua.
squishyContent = []
if os.path.isfile(root + os.path.sep + "squishy"):
self.Log("Parsing Squishy")
with open(root + os.path.sep + "squishy") as squishyFile:
lines = squishyFile.readlines()
squishyFile.close()
for line in lines:
if line.startswith("Module "):
path = line.replace('Module "', '').replace('"', '').replace("\n", '').replace(".", "/") + ".lua"
Just need some examples/help in getting through this.
This might sound silly, but the easiest approach is to convert everything you told us about your task to code.
for line in lines:
# if the line doesn't start with "Module ", ignore it
if not line.startswith('Module '):
continue
# As you said, there are 3 columns. They're separated by a blank, so what we're gonna do is split the text into a 3 columns.
line= line.split(' ')
# if there are more than 2 columns, use the 3rd column's text (and remove the quotes "")
if len(line)>2:
line= line[2][1:-1]
# otherwise, ...
else:
line= line[1] # use the 2nd column's text
line= line[1:-1] # remove the quotes ""
line= line.replace('.', os.path.sep) # replace . with /
line+= '.lua' # and add .lua
print line # prove it works.
With a simple problem like this, it's easy to make the program do exactly what you yourself would do if you did the task manually.

How can I import and use labels from one Stata file to the current?

I have file aa with a variable x which is labeled with value label x_lab. I would like to use this value label on the variable x of Stata file bb:
use bb, clear
label value x x_lab
How can I import the value label x_lab?
You can use label save, which saves value labels in a do-file:
label save x_lab using label.do
use bb, clear
do label.do
See Stata help for label.
This answer technique didn't work for me as I wanted the variable labels created with e.g. label var connected "connected household", not the value labels.
Instead I used this advice: http://statalist.1588530.n2.nabble.com/st-How-to-export-variables-window-td3937733.html
*************
sysuse auto, clear
log using mylog, name(newlog) replace
foreach var of varlist _all{
di _col(3) "`var'" _col(20) "`:var label `var''"
}
log close newlog
//translate from proprietary format
translate mylog.smcl mylog.txt, replace
!start mylog.txt
*************
To fix the labels that extended over multiple lines so they just used a single one, I then replaced the \n > for the oversized labels with nothing (in regex mode in atom). I could easily save into TSV from there.
Specifically:
Clean up header and footer text in the logfile output.
On Mac: use "\n" instead of "\r\n".
On Windows: first "\r\n -> ""
then whitespace at beginning "\r\n " --> "\r\n"
then convert whitespace with 3 or more spaces in middle to tabs " +" --> "\t"
(Edit manually additional errors on tab if there are still some left)
save as mylog.tsv
open in Excel, and use table of labels as needed.