Finding just the searched string in all files - sublimetext2

Is is possible to find a specific string in all files and just display the string instead of line in which search result. I have got a huge project with some css tag starting with a string. Would like to find number of css tags starting with those pattern string. Help would be appreciated. Thank you.
There is an example
File One
This is a sample <div class="myapp-bold">Text</div>
File Two
This is a sample <div class="myapp-small myapp-bold">Text</div>
In results, I would like to see
File One
myapp-bold
....
File Two
myapp-small myapp-bold

You can search!!
1)Drag and drop your project folder to sublime.
2) Press ctrl+shift+ F
3) enter the search value in Find:
4) click on Where: and add the complete folder where you want to search

Related

Sublime search specfic keywords as function withn the same file

In my project file extension is .ttcn and all the function in that file start with testcase name_of_the_function.
Is there any Sublime plugin exist that can list all the function that is start with keyword testcase followed by test case name?
FYI, most of the common programming languages sublime list all the functions name with shortcut ctrl'r. Thanks in advance for any suggestion or recommendation !
You can use the Find in Files functionality (Find -> Find in Files...). In the Find: field, make sure the first button (Regex) is selected, as well as the last two (Context and Use Buffer), then enter ^testcase. Add the directory you'd like to search in the Where: field, and make sure the Replace: field is empty. Hit the Find button, and a new tab will open showing all lines that begin with testcase.

Find, isolate, reconstruct en replace string in database

I have a very practical question. I have got about 400 articles in my database and in those articles i have links to other articles. During conversion the links were broke. We inserted new menu-link items manually in our CMS. I want to make a script that looks for an (article)id and replace the menu-item id within the internal link for a new menu-item id.
For example:
this is the old internal link in table twsf_content, column introtext:
index.php?option=com_content&view=article&id=140&Itemid=613“v.d.Hermels Hoeve”</a>
this must be the new link in table twsf_content:
index.php?option=com_content&view=article&id=140&Itemid=397“v.d.Hermels Hoeve”</a>
the only thing that changed is the Itemid (397 in stead of 613).
We can find article&id (in this case 140) in another table (twsf_menu, column link) and determine what Itemid must be: 397 (column Id) in stead of 613.
There can be more links in one article.
In short: we want to find all links in all articles and replace the Itemid for the new Itemid.
Can somebody give me the code to do this?
Thanks in advance!
Extract the stuff to a CSV file, work on that with sed and awk and load it back to the database would be my approach. MySQL isn't good in recursively working with regex and this looks like one-off job.

Parse tab separated text file in Google Sheets

I have a txt file available on the web which contains tab separated values (TSV/CSV) like this:
Product_IdtabColortabPricetabQuantityItem1 tabRed tab$5.2 tab5Item2 tabBlue tab$7.5 tab10
I imported the txt file into a Google Spreadsheet using the IMPORTDATA(url) formula. The problem is that now I need to split the text to columns. I tried the following formulas without success:
Split(A1,"\t")
Split(A1," ")
Split(A1,"<tab>")
another thing I tried is to to use the Substitute function, but I just can't figure out how to match the Tab character in Google Spreadsheets?
Pages strips tabs by default when you paste text using a standard paste. Tab delimited data can be pasted and automatically parsed using:
Right Click -> Paste special -> Paste values only
IMPORTDATA(url) seems to handle tabs automatically, as others have mentioned before, if the URL ends in ".tsv".
I had trouble trying to import a file from Dropbox even though the file was named "something.tsv", because the url was
"https://www.dropbox.com/s/xxxxxxx/something.tsv?dl=1"
I managed to solve the problem by adding a dummy query parameter to the url:
"https://www.dropbox.com/s/xxxxxxx/something.tsv?dl=1&x=.tsv"
NOTE: I know this question was asked back in 2014 and I am answering this question some 5 years later. I am posting the answer here in hopes that someone else who googles their way here will be saved the headache and can be helped by how I devised a solution.
SUMMARY OF THE ISSUE: By default the IMPORTDATA() function will properly process a tab-delimited file only if the file name ends with the extension .TSV
UPDATE Nov 14, 2019:
In a comment below, Poul shared that he has found an undocumented parameter for the IMPORTDATA() function by which you can specify the delimiter to split the data. As of writing this, the official documentation makes no reference to this delimiter.
In effect the documentation should look something like the following:
IMPORTDATA("url","delimiter")
So, if you wanted to force a file to be split on the TAB character, it would look something like
IMPORTDATA("url","\t")
PRIOR ANSWER:
UPDATE: I am leaving my original answer just in case it might be helpful if the answer above, which includes undocumented functionality, does not continue to work.
ORIGINAL ANSWER: After seemingly countless attempts, I figured out how to coax Google Sheets into importing a tab-delimited file regardless of the extension.
For those looking for the quick and dirty answer, copy the following into a cell of a Google Sheet to give it a try:
=ARRAYFORMULA(IFERROR(SPLIT(IMPORTDATA("https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3_Latin1.tab"),CHAR(9),FALSE,FALSE)))
For those that want to know a bit more, I will try to explain how each of the nested functions are helping to create the final solution:
=ARRAYFORMULA( IFERROR( SPLIT( IMPORTDATA(URL-HERE) ,CHAR(9),FALSE,FALSE) ) )
IMPORTDATA() - the primary function that pulls in the data file from the web
SPLIT - split the row by tab, note the use of char(09) to generate the tab character; also note the use of FALSE for the last parameter which was required in my case to ensure empty cells were not collapsed together
IFERROR - used to catch situations where an import might fail, the error will be trapped and not returned to the spreadsheet
ARRAYFORMULA - this function ensures that every line in the file is parsed; without this, only the first line of the file would be returned to the spreadsheet
It turns out that IMPORTDATA(url) can import a tab separated file, but it expects the file name to have the .tsv extension. This is inconsistent with Excel, where a tab-separated export results in *.txt.
If you can ensure that you use a .tsv extension, then your problem is solved.
You can also use the Sheets UI to import the file (into a new Spreadsheet). Select File > Import..., then Upload > Select a file from your computer. When the file selection dialog opens, paste the URL into the file name field, and click Open. The file will be downloaded to your PC then uploaded to Drive, through the Import dialog that will let you choose the delimiter.
(Validated on Windows 8.1 with Chrome; I don't know how this will behave on other OSes or browsers.)
Edit: See this gist.
importFromCSV(string fileName, string sheetName)
Populates a sheet with contents read from a CSV file located in the user's GDrive. If either parameter is not provided, the function will open inputBoxes to obtain them interactively.
Automatically detects tab or comma delimited input.
I had luck using split() and indicating only a single space as the delimiter, even though the data i pasted in had tabs separating each "column": =SPLIT(A1, " ", True) where A1 had data separated by 1 or more spaces. It seems that pasting in TSV data results in conversion from tabs to spaces.
This could be done in two steps leveraging the fact that tab is essentially multiple spaces.
Steps are as follows:
Select the columns which have tab separated data. Then trim tab to single space by using Data -> Data cleanup -> Trim whitespaces.
Now usual Data -> Split text to columns should work out of the box or after selecting space as separator.

I am trying to figure out how to set the "IndexableText" field in a google drive file. Can someone provide a code example in java?

I am trying to figure out how to set the "IndexableText" field in a google drive file. Can someone provide a code example in java? Also, does the field need to be rewritten every time the file is updated? If yes, then, is there any way of reading the contents of this field?
You simply have to use the setIndexableText method of the File class when inserting or updating a document.
Start from the sample at https://developers.google.com/drive/v1/reference/files/insert#examples and edit it as in the following snippet:
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// add this line
body.setIndexableText(new IndexableText().setText("your text content"));
The indexable text field must be rewritten every time the file is updated, but it is a write-only field so you can't read its content.

Find/Replace but Increment Value

I have an .HTML file that has many photos attached to it for displaying a photo gallery. I'm replacing old photos with new ones, and I'm thinking there must be a more intelligent way than simply copying and pasting repetitive file names.
I would love to be able to replace and increment a file name on each replace, starting at a base file name of my choosing. For example...
...images/69thStreet010.jpg
...images/69thStreet011.jpg
...images/69thStreet012.jpg
Basically performing a CTRL+F and REPLACE '69thStreet010.jpg' with...
...images/xyz001.jpg
...images/xyz002.jpg
...images/xyz003.jpg
And so on until I want it to stop. Anyone here have any suggestions? Thanks a lot!
UPDATE: I should also add, I'm using Notepad++ to edit my files.
Look into the Column Editor feature within Notepad++. You can do a block select on the area you want to increment and then give it a starting/ending range and you're all set.
I was in a similar situation recently. I did a little bit of regular expression search/replace to get my filenames into my "default" format with some padded "000" where I wanted my incrementing to start. After that, I used Shift+ALT to block select the 000s and used the editor to do the rest of the work.
OK, I came up with a Notepad++ solution.
It does require you to install the Notepad++ plugin PythonScript.
It is a TextPad-like incremental replace.
i.e.
Search and replace integer values within a string
replacing incrementally starting with 1 (0 is the default starting value):
In your case it would be
Search: ...images/69thStreet[0-9]+.jpg
Replace: ...images/xyz00\i(1).jpg
Install the PythonScript plugin.
Save the code below as a PythonScript and associate a shortcut (i.e. Ctrl+i) to it:
Then open your html file in Notepad++ and run the script below on your html file.
When prompted by the search replace dialogue, enter the following 2 lines:
...images/69thStreet[0-9]+.jpg
...images/xyz00\i(1).jpg
Now, all instances of
...images/69thStreet010.jpg
...images/69thStreet011.jpg
...images/69thStreet012.jpg
will become
...images/xyz001.jpg
...images/xyz002.jpg
...images/xyz003.jpg
Here is the PythonScript code
from Npp import *
import re, string
# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
editor.beginUndoAction()
expression = notepad.prompt("Enter the search string on the first line, followed by Ctrl+Enter, \n" +
"followed by the replace string on second line",
"Incremental Search/Replace" ,
"")
expressionList = re.split(r"[\n\r]+", expression)
if len(expressionList) == 2:
foundCount = [0]
def incrementalReplace(parmReplaceStr,parmFoundCount):
varPatternI = r'\\i\((?P<starting>[0-9]+)\)'
varPatternIi = r'\\i'
varPatternISearch = re.search(varPatternI , parmReplaceStr)
if varPatternISearch != None:
varFoundCount = int(varPatternISearch.group('starting')) + parmFoundCount[0]
varReplaceString = re.sub(varPatternI ,str(varFoundCount ),parmReplaceStr)
elif re.search(varPatternIi, parmReplaceStr) != None:
varReplaceString = re.sub(varPatternIi,str(parmFoundCount[0]),parmReplaceStr)
parmFoundCount[0] = parmFoundCount[0] + 1
return varReplaceString
# Do a Python regular expression replace
editor.searchAnchor()
while editor.searchNext(0x00200000,expressionList[0]) != -1:
editor.replaceSel(incrementalReplace(expressionList[1],foundCount))
editor.lineDown()
editor.searchAnchor()
# End the undo action, so Ctrl-Z will undo the above two actions
editor.endUndoAction()
If your S&R supports Regex, use this.
Search term:
images/69thStreet([0-9]+).jpg
Replace term:
images/xyz$1.jpg
I just use Excel & Notepad++
Create a column of incrementing numbers in Excel. Then in the next (or previous) column, put in the line you wish to merge w/ the incrementing numbers. For instance:
file00 | 1 | .jpg
file00 | 2 | .jpg
Etc.
Then copy/paste the thing into Notepad++ (or use Excel's CONCATENATE function if the job is simple) and do a replacement.
It's time for you to learn scripting languages. Python/Ruby/Perl can do this in a few lines by using simple regular expressions and a directory listing.
notepad++ allows you to make multi line editing. But the main problem here is to get as quick as possible all the file names from the directory where they are.
In the past I had similar challenge that I solved this way.
This works almost on all win vers.
To make a list of all files in a directory create a bat file into the dir itself.
copy and paste there the following batch code
dir /b > filelist.txt
Save the file with name
makefilelist.bat
Not important the name you give it: the important thing is the file extension .bat
Double click on the bat file just saved: the batch script executes a clean dir command inside the directory in witch it is executed redirecting the output to the file filelist.txt
In less than one sec you have the output saved into the filelist.txt witch will be similar to the following:
filelist.txt
Image File Name 01.gif
Image File Name 02.gif
Image File Name 03.gif
Image File Name 04.gif
Image File Name 05.gif
Image File Name 06.gif
Image File Name 07.gif
Image File Name 08.gif
Image File Name 09.gif
Image File Name 10.gif
Image File Name 11.gif
Image File Name 12.gif
Image File Name 13.gif
Image File Name 14.gif
Image File Name 15.gif
Image File Name 16.gif
Image File Name 17.jpg
Image File Name 18.jpg
Image File Name 19.jpg
Image File Name 20.jpg
Image File Name 21.jpg
Image File Name 22.jpg
Image File Name 23.jpg
Image File Name 24.jpg
Image File Name 25.jpg
Image File Name 26.jpg
Image File Name 27.jpg
Image File Name 28.jpg
Image File Name 29.jpg
Image File Name 30.jpg
Image File Name 31.jpg
Image File Name 32.jpg
Image File Name 33.PNG
Image File Name 34.PNG
Image File Name 35.PNG
Image File Name 36.PNG
Image File Name 37.PNG
Image File Name 38.PNG
Image File Name 39.PNG
Image File Name 40.PNG
Image File Name 41.PNG
Image File Name 42.PNG
Image File Name 43.PNG
Image File Name 44.PNG
Image File Name 45.PNG
Image File Name 46.PNG
Image File Name 47.PNG
Image File Name 48.PNG
makelist.bat
Of course the names logged into the file list may vary... The script logs every file, no matters if it is in sequence or not or if its name is a random name or contains date time (time stamp) etc.: it logs everything is into the same dir in witch is executed...
Now you can open filelist.txt with notepad++: first delete the lines of the list that report the unwanted files:
makelist.bat
filelist.txt
This operation is necessary cause the script lists also itself and the filelist.txt.
Then with multi line editing tool add the tag around all lines at once, or everything else needed to built the photo gallery, even a javascript array, etc... in the end copy and paste the finished job to your image gallery file under coding.
Done. Easy as drinking a glass of water: it is more difficult to explain than to do! Granted. ;-)
Improvements:
It is possible to get a list of just the jpg files by modifying the batch command like the following:
dir *.jpg /b > filelist.txt
Image File Name 17.jpg
Image File Name 18.jpg
Image File Name 19.jpg
Image File Name 20.jpg
Image File Name 21.jpg
Image File Name 22.jpg
Image File Name 23.jpg
Image File Name 24.jpg
Image File Name 25.jpg
Image File Name 26.jpg
Image File Name 27.jpg
Image File Name 28.jpg
Image File Name 29.jpg
Image File Name 30.jpg
Image File Name 31.jpg
Image File Name 32.jpg
The same with other file extensions.
There is. Create your list of photos using a python script that looks at whatever directory you want, and renames or just lists all the file names. Then go from that to a python script that generates the HTML you need (should be very easy at this point). Then copy & paste that.
Python is very easy to use, you will be able to download it in 5 minutes & find a tutorial for reading / changing file names in another 10 minutes.