I have a csv file containing info for tv-series and each tv-series has its own macro. I can get all info without any problems using {{!COL1}} etc.
But I need some help on the scenario below.
tv-series.csv
Game of Thrones, 2011, Season 2
The Walking Dead, 2015, Season 5
etc.
If I want to get the title of a tv-series I will simply use {{!COL1}}, and for year {{!COL2}}
But I sometimes add new tv-series and the order of them compeletly changes in csv file. Then I have to modify all line #s in all macros manually.
Is there a way to determine the line number based on the firt column (e.g. Game of Thrones)? The info will not change, just the line numbers of them will change. Sorry for my terrible English, I hope I could tell my problem and need some advice.
My code so far
VERSION BUILD=8910303 RECORDER=FX
TAB T=1
SET !DATASOURCE tv-series.csv
SET !DATASOURCE_LINE 2 => This # should change based on first column
TAG POS=1 TYPE=TEXTFIELD FORM=NAME:title ATTR=ID:titlebox CONTENT={{!COL1}}
Use the command 'EVAL' and 'switch'-clause. As an example:
...
SET !DATASOURCE tv-series.csv
SET !DATASOURCE_LINE 1
SET lineNumber EVAL("switch ('{{!COL1}}') {case 'Game of Thrones': s = 2; break; case 'Something Else': s = 5; break; /* etc. */}")
SET !DATASOURCE_LINE {{lineNumber}}
...
Related
The address of Japan is written in many sites as 〒000 - 0000.
From this, I would like to extract only numbers using imacros.
In other words, I want to remove 〒 and -.
I want to copy the extracted data, save it on the clipboard and paste it in another place.
Thank you.
(chrome 70.0.3538.102, Win10_x64)
Posting as a separate Solution, as the Input from the Extract is now "a bit" different and changes the Syntax in 'EVAL()' quite a bit, even if I tried to reuse a bit the same Syntax with the same Commands like in Answer_#1. (And that gives a 2nd Code Example...)
SET !EXTRACT "〒 000-0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(2); y=x.split('-'); z=y[0]+y[1]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
And again, there would be more than 10 different ways to implement the same Functionality to get the same Result...
"Nice" to select the 'Chrome' + 'Firefox' Forum Tags but more useful would be if you had mentioned your FCI for both Browsers..., but the following Implementation for example should work in both Browsers for all iMacros Versions:
SET !EXTRACT "〒000 - 0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(1); y=x.split(' '); z=y[0]+y[2]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
"for example" => as you could implement the Functionality that you want in more than 10 ways using all kinds of different Combinations with other JS String Methods...
(I didn't include the Content of '{{!CLIPBOARD}}' in the 'PROMPT' as this is not supported on CR, but a 'Paste' from your OS Clipboard in 'Notepad' for example should still work...)
As shown in the picture "Before" below, each column separated by comma is not aligned neatedly. Is there any method to align each column vertically like the display effect in Excel?
The effect I wish is shown in the picture "After".
Thanks to #Martin S , I can align the file like the picture "Method_1". As he has mentioned, some characters still cannot align well. I was wondering if this method could be improved?
You can use the TextFX plugin:
TextFX > TextFX Edit > Line up multiple lines by ...
Note: This doesn't work if the file is read only.
http://tomaslind.net/2016/02/18/how-to-align-columns-in-notepad/
Update 2019: Download link from SourceForge
Maybe not exactly what you're looking for, but I recently added a CSV Lint plug-in to Notepad++ which also adds syntax highlighting for csv and fixed width data files, meaning each column gets a different color so it's easier to see.
You can use this python plugin script which utilizes the csv library which takes care of quoted csv and many other variants.
Setup:
Use the plugin manager in Notepad++ to install the "Python script" plugin.
Plugins->Python Script->New Script (name it something like CSVtoTable.py)
Paste the following python script into the new file and save:
CSVtoTable.py
import csv
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# To right align - change < to >
fmt_str = ' '.join(['{{:<{0}}}'.format(x) for x in col_widths]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
Open your CSV file in notepad++
Click on Plugins->Python Script->Scripts->(The name you used in step 2)
A new tab with the formatted data should open.
Update (right aligned numbers & left aligned strings):
Use the following python script if you want to right align number fields from the CSV - it looks at the second line of the csv to determine the types of the fields.
import csv
import re
num_re = re.compile('[-\+]?\d+(\.\d+)?')
inputlines = editor.getText().split('\n')
# Get rid of empty lines
inputlines = [line.strip() for line in inputlines if line.strip()]
reader = csv.reader(inputlines, delimiter=',')
csvlist = [line for line in reader]
# Transpose to calculate the column widths and create a format string which left aligns each row
t_csvlist = zip(*csvlist)
col_widths = [max([len(x) for x in t_csvlist[y]]) for y in range(len(t_csvlist))]
# Numbers get right aligned
type_eval_line = csvlist[1 if len(csvlist)>1 else 0]
alignment = ['>' if num_re.match(item) else '<' for item in type_eval_line]
# Compute the format string
fmt_str = ' '.join(['{{:{0}{1}}}'.format(a,x) for x,a in zip(col_widths,alignment)]) + '\r\n'
text = []
for line in csvlist:
text.append(fmt_str.format(*line))
# open a new document and put the results in there.
notepad.new()
editor.addText(''.join(text))
Notepad++ CSVLint
Install CSVLint Plugin
Open CSV file. Or manually set Language > CSVLint. This will give you nicely colored output.
To reformat do this:
Open lower pane: Plugins > CSV Lint > CSV Lint Window.
Click the Reformat button. Check the box Align vertically (not recommended). -- This may screw up your data, so think twice before clicking OK.
Reformatted output:
If you want to try this yourself: Here is my sample input:
TIMESTAMP_START,TIMESTAMP_END,TA_ERA,TA_ERA_NIGHT,TA_ERA_NIGHT_SD,TA_ERA_DAY,DA_ERA_DAY_SD,SW_IN_ERA,HH,DD,WW-YY,SW_IN_F,HH
19890101,19890107,3.436,1.509,2.165,6.134,2.889,100.233,283.946,1.373,99.852,2.748,1.188
19890108,19890114,3.814,2.446,2.014,5.728,2.526,91.708,286.451,1.575,100,100.841,0.742
You could use Search&Replace to change all occurrences of , to ,\t. This will add a tab after each ,.
This method has however some drawbacks:
you effectively add white-space characters to your document (in case you need to edit and save it).
This works well only if the difference (in terms of number of characters) between the longest and the shortest numbers is less than 1 tab-size (usually 4 characters).
I have only just started using Adobe Brackets for HTML development. As a programming newcomer, I am still not savvy enough to look in all the right places to change defaults. When I type a beginning tag in Brackets (HTML) like < p >, the editor automatically adds the ending tag < /p >, assuming that I will enter text between the two tags. So I get < p > < /p >. Often I want to put the tags around existing text and do not want the auto completion of the end tag upon entering the beginning tag. How do I change the default in Adobe Brackets so that I do not get the auto-completion of the end tag?
You can do this by setting the dontCloseTags option in the Brackets preferences file.
Go to the Debug menu and select Open Preferences File. You will see a side-by-side view of defaultPreferences.json on the left and brackets.json on the right. These are Brackets' default settings and your settings file, respectively. defaultPreferences.json lists all the possible options that can be set and their default values, but the file itself can't be modified.
Look at the comments in defaultPreferences.json for closeTags. What we care about is dontCloseTags.
Set dontCloseTags inside of closeTags. For example, my defaultPreferences.json file looks like this:
{
"fonts.fontSize": "12px",
"fonts.fontFamily": "'SourceCodePro-Medium', MS ゴシック, 'MS Gothic', monospace",
"themes.theme": "dark-theme",
"useTabChar": true,
"tabSize": 5
}
And so I would set it up like this, adding a comma after the last entry before starting a new one below:
{
"fonts.fontSize": "12px",
"fonts.fontFamily": "'SourceCodePro-Medium', MS ゴシック, 'MS Gothic', monospace",
"themes.theme": "dark-theme",
"useTabChar": true,
"tabSize": 5,
"closeTags": {
"dontCloseTags": ["p", "img"],
"whenOpening": true
}
}
I set whenOpening to true because I found that sometimes Brackets won't autocomplete any tags without me asserting that value, even though it's the default.
Press Ctrl + S to save your preferences and then close the two files.
Click on the icon next to the settings icon next to the Left heading in the sidebar, then select No Split. This will remove the two columns.
I hope this helps, and have fun looking at the other settings in defaultPreferences.json, since Brackets won't add a front-end for those settings for a while (it's in the works). Just make sure to match the syntax exactly as it is in defaultPreferences.json (except for the comments). JSON also wants commas between stuff inside {} and [], but do not add a trailing comma after the last item in each grouping. If the option you want is inside another option (for example, dontCloseTags is inside of closeTags{}), you need to include the main option and its grouping symbol thing.
Just use a boolean "false" for the value of the field name(s) if you want to shut that object to not function at all
"closeTags": {
"whenOpening": false,
"whenClosing": false
}
This sets the value of the closeTag field with Boolean defined values of two more objects which results with all auto-completing, closing tags to stop working.
After saving your changes, be sure the new file is loaded by restarting the application. All save does is saves your edits, any changes will not be seen until you restart the application.
I'm writing HTML with gvim, but what annoys me is that the omni-complete always delete my previous word, even my previous selected ones.
For example, assume I'm writing the following code**('_' means the cursor, hereafter)**:
<a style="_" ></a>
After I Press ^X-^O, it pops out the hint list, and I select "color:"
<a style="color:_" >
And I Press ^X-^O again, it does pops out the proper hints("rgb(", "#"), but it deletes the previous word in the meanwhile, like this:
<a style="rgb(_" >
Can anyone give me some help? Thanks a lot. And this is my gvimrc:
set guifont=文泉驿等宽微米黑\ 14
colorscheme neverness_modified
set number
set guioptions-=T
winpos 0 0
set columns=1000
set lines=1000
set fileencodings=utf-8,gb18030
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
filetype on
filetype indent on
syntax on
set cindent
set completeopt+=longest
function Maximize_Window()
silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
" ========================
" TagList
" ========================
set tags+=/home/fish47/.vim/tags/STL.tags
" ========================
" TagList
" ========================
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
" ========================
" WinManager
" ========================
let g:winManagerWindowLayout='FileExplorer|TagList'
WMToggle
" ========================
" OmniCppComplete
" ========================
set nocp
filetype plugin on
let OmniCpp_SelectFirstItem=2
let OmniCpp_MayCompleteDot=1
let OmniCpp_MayCompleteArrow=1
let OmniCpp_MayCompleteScope=1
set showcmd
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
This is a bug in the htmlcomplete.vim script. You can work around this by inserting a <Space> between property and value, as romainl has pointed out.
Please submit a bug report (basically a link to this page) to the script's author, Mikolaj Machowski; his email address is in the script's header; the script is located at autoload/htmlcomplete.vim in the Vim install directory.
As the last change was from Apr-2011, there's a good chance the author is still maintaining it. Should you not get a response, please inform the vim_dev mailing list (cp. http://www.vim.org/community.php; you need to register first) about this; hopefully, someone else will pick it up.
Let csscomplete.vim to handle the html completion may be a solution to my problem. You can do that by adding "autocmd FileType html set omnifunc=csscomplete#CompleteCSS" in gvimrc.
It's a bug and a regression for a newer version of vim. This csscomplete.vim plugin was written for an earlier version and you using a newer version, there's an unexpected regression.
If you hack the plugin, you'll see the delete happens because it moves the cursor in reverse looking for the most obvious context, and that reverse cursor movement gets interpreted as an erase by your vim.
For me the bug was in these lines:
...
let compl_begin = col('.') - 2
while start >= 0 && line[start - 1] =~ '\%(\k\|-\)'
let start -= 1
endwhile
So yeh there's yer problem: the variable named start is passed back to vim through omnifunc and vim used to leave the existing text as-is, but newer versions interpret that motion as an erase.
So change the second while clause condition asserting the hyphen, and now you're off to the races. But that exposes a new problem, typing a letter and initiating omnifunc slows down as csscomplete.vim bogs down. But hey, one problem at a time huh.
It's like buying a car with the steering wheel mounted on the roof. It's like yeh that's not going to work bub. But this is Vim, if you're not in this for the low level hacking, then you're in the wrong machine shop.
I have one table, and I need to remove a specific text from a specific field. This field contains a full URL of an image, I need to remove the URL and just keep the image filename.
So:
Current date: fieldname: www.example.com/photo.jpg
What I want to do is remove www.example.com/ from all of the entries for this field.
I know how to use the search and replace function, but I don't know how to leave part of the data intact.
This is what I've used but can't modify it to make it work the way I want:
UPDATE table SET oc_upload1 = REPLACE(oc_upload1,'newtext') WHERE oc_upload1 LIKE "oldtext"
Is this possible? If so, how? Thank you!
This should do:
UPDATE table
SET image = REPLACE(image, 'www.example.com/','')
but, it's possible that image contains 'www.example.com/' as part of image file name so to be extra safe and replace only the first occurence of www.example.com
UPDATE table
SET image = SUBSTRING(image, LENGTH('www.example.com/') + 1)
WHERE image LIKE 'www.example.com/%'
But if You really, really just want the file name and not path to the file You can also use:
UPDATE table
SET image = SUBSTRING_INDEX(image,'/',-1)
Note that above statement will change 'www.example.com/images/01/02/daisy.jpg' to 'daisy.jpg', not 'images/01/02/daisy.jpg'. It also wont change rows that does not contain '/' in image.