Command to "format" txt Files - command

I have several TXT files like the example bellow in a certain solder:
5600001254545 - Bar code
12 - Quantity
5600000785487 - Bar code
250 - Quantity
I need to writte a code to place the line of the quantity in front of the code bar, separated by; in all the files without opening them one by one or doing it on Excel.
Can you please help me?
Regards,

Try to do it with a text editor supporting regular expressions (Maybe Editplus, Textpad++, ...).
Open your text files with such editor and replace "Bar code\n" by "Bar code;". This way you will have just one line with both the barcode and the quantity data.

Related

Visual Studio Code select same position above and below not the whole line before and after (see image)

I'm using visual studio code and run into a weird problem. I'm not sure how I got here - I could have accidently pressed a shortcut unknowingly.
I'm trying to select a phrase, link or anything that crosses multiple lines (whether the lines are true lines or due to word wrap). When I select multiple lines, it doesn't automatically select the text at the start and end between the two points. Rather, it just selects the length of text for that line and repeats it in the subsequent lines. See the image below to understand.
Image of issue
As you can see, I am trying to select the words from "the" to the end of "sub". Instead of selecting all the words between the two, it selects the text "the instru" and selects every line with the same amount of characters/length.
In order to show what I am expecting, I have pasted the text into Notepad and done the same thing.
What I am expecting
As you can see, all the words between "the" and "sub" are selected.
If anyone has any idea about how to fix this, I would be greatly appreciative.
Below is a copy of the text if the images don't display.
Follow the instructions below for a click guide to retire and/or add 'School'.
Best practice if there is a change in 'School' structure would be to 'retire' any existing school setup that is no longer required and add the new sub school information. The reason why we don't just edit existing school names (typically) is due to leaving historical data intact.
Try using ctrl+shift+P and typing "Toggle Column Selection Mode"

Select nonadjacent lines containing a common phrase in vscode

I have an HTML file that has around 700 of my bookmarks. Each line has link and a tag like the following:
<li>Strunk, William, Jr. 1918. The Elements of Style</li>
The file has multiple lines with the same tags. I want to group the lines with the same tag next to each other. I was trying to do it in vscode. I can select multiple occurrences of the same phrase with Ctrl+Shift+L, but I could not select the lines. Is there a way for doing this?
After your comment below that clarified what you are trying to do I think you will find this easier than your solution.
Select the text to check.
Ctrl-Shift-L selects all occurrences. The command is Select All Occurrences of Find Match - if that is bound to something else on your OS, use that.
Ctrl-L will select the entire line. (Changed from Ctrl-i in Feb. 2019.) That is using the command Expand Line Selection - again find that command in your Keyboard Shortcuts and use the same command.
Cut and paste them where you want.
There is also an extension vscode-dup-checker that will find and delete duplicate lines. I don't know if you actually want to delete the duplicates though.
I added a gif to show it in action - it only uses steps 1-4 above:
Ok, I found one method that works. I don't know if it the best though.
After Ctrl+Shift+L, you have cursors on all the lines with that phrase. Then pressing Home will take you to the beginning of all of them and Shift+End then will select all those lines on which you have the cursor. Then cut the text and paste it wherever you wish. Came out to be pretty useful for me while I was editing a html file with 700 links.

How can I remove duplicate lines in Visual Studio Code?

Say you have the following text:
abc
123
abc
456
789
abc
abc
I want to remove all "abc" lines and just keep one. I don't mind sorting. The result should be like this:
abc
123
456
789
If the order of lines is not important
Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: How do I find and remove duplicate lines from a file using Regular Expressions?)
Control+F
Toggle "Replace mode"
Toggle "Use Regular Expression" (the icon with the .* symbol)
In the search field, type ^(.*)(\n\1)+$
In the "replace with" field, type $1
Click ("Replace All").
If the order of lines is important so you can't sort
In this case, either resort to a solution outside VS Code (see here), or - if your document is not very large and you don't mind spamming the Replace All button - follow the previous steps, but in steps 4 and 5, enter these:
(based on Remove specific duplicate lines without sorting)
Caution: Blocks for files with too many lines (1000+); may cause VS Code to crash; may introduce blank lines in some cases.
search: ((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s]*?)^\2$(?:\n)?
replace with: $1
and then click the "Replace All" button as many times as there are duplicate occurrences.
You'll know it's enough when the line count stops decreasing when you click the button. Navigate to the last line of the document to keep an eye on that.
Coming in vscode v1.62 is a command to eliminate duplicate lines from a selection:
Delete Duplicate Lines in the Command Palette
or
editor.action.removeDuplicateLines as a command in a keybinding
(there is no default keybinding for this command)
Here is a very interesting extension: Transformer
Features:
Unique Lines As New Document
Unique Lines
Align CSV
Align To Cursor
Compact CSV
Copy To New Document
Count Duplicate Lines As New Document
Encode / Decode
Filter Lines As New Document
Filter Lines
Join Lines
JSON String As Text
Lines As JSON String Array
Normalize Diacritical Marks
Randomize Lines
Randomize Selections
Reverse Lines
Reverse Selections
Rotate Backward Selections
Rotate Forward Selections
Select Highlights
Select Lines
Selection As JSON String
Sort Lines By Length
Sort Lines
Sort Selections
Split Lines After
Split Lines Before
Split Lines
Trim Lines
Trim Selections
Unique Lines
Removes duplicate lines from the document Operates on selection or
current block if no selection
Unique Lines As New Document
Unique lines are opened in a new document Operates on selection or
current block if no selection
I haven't played with it much besides the "Unique Lines" command but it seems quite nicely done (including attempting a macro recorder!).
To add to #Marc.2377 's reply.
If the order is important and you don't care that you just keep the last of the duplicate lines, simply search for the following regexp if you want to only remove duplicte non-empty lines
^(.+)\n(?=(?:.*\n)*?\1$)
If you also want to remove duplicate empty lines, use * instead of +
^(.*)\n(?=(?:.*\n)*?\1$)
and replace with nothing.
This will take a line and try to find ahead some more (maybe 0) lines followed by the exact same line taken. It will remove the taken line.
This is just a one-shot regex. No need to spam the replace button.
This now also takes the comment of #awk into account, in where the last line has to have a linefeed in order to be identified as a duplicate. This is no longer the case now by excluding the \n from the line to search and adding a $ to the line found.
I just had the same issue and found the Visual Studio Code package "Sort lines". See the Visual Studio Code market place for details (e.g. Sort lines).
This package has the option "Sorting lines (unique)", which did it for me. Take care of any white spaces at the beginning/end of lines. They influence whether lines are considered unique or not.
Install the DupChecker extension, hit F1, and type "Check Duplicates".
It will check for duplicates and ask if you want to remove them.
Try find and replace with a regular expression.
Find:
^(.+)((?:\r?\n.*)*)(?:\r?\n\1)$
Replace:
$1$2
It is possible to introduce some variance in the first group.
If you don't mind some Vim in your VS Code. You can install Vim emulation plugin.
Then you can use vim commands
:sort u
It will sort lines and it will remove duplicates
Sublime Text 3
It has blisteringly fast native permutation functions.
Edit > Permute Lines > Unique or ⇧⌘U, and
Edit > Permute Selections > Unique
Visual Studio Code is my daily driver. But, I keep Sublime Text on standby for these situations.
Not actually in Visual Studio Code, but if it works, it works.
Open a new Excel spreadsheet
Paste the data into a column
Go to the Data tab
Select the column of data (if you haven't already)
Click Remove Duplicates (somewhat in the middle of the bar)
Click OK to remove duplicates.
It is not the best answer, as you specified Visual Studio Code, but as I said: If it works, it works :)

Convert Tabs-as-spaces width

I have many source code files which are idented with 8 space characters, I want to convert these to 4 character indents. What is the best way of doing this? A technique using eclipse would be preferable.
Select the project(s), then press Ctrl+H to open the Search dialog (or click the Search > File menu).
Make sure the File Search tab is selected at the top.
Enter 8 spaces into the Containing text: field
Select your File name pattern (probably *.java or just *)
Select the scope (probably Selected Resources)
Press the *Replace... button.
As I said in the comments above, however, using spaces for indentation is a fool's game; tabs are the proper abstraction for indentation so that you don't have this problem.

Copy code example from Zend Site

How would you copy the code from this example page
http://framework.zend.com/manual/en/learning.quickstart.create-layout.html
(Below the text "Now that we've initialized Zend_Layout and set the Doctype, let's create our site-wide layout:" )
A simple copy paste will also copy the line number or #. Any tricks ?
I hate these line numbers as well. The way I do it:
Copy the text to your favorite text editor (notepad won't do, Word for example would) and block-select using the ALT Key.
Let me give you an example with Notepad++. here I copied text from the said site with all line numbers included. Now I just hold the ALT button and select normally with my mouse (or using SHIFT+arrow keys). The result of me selecting only the code sans the line numbers you see in the following screenshot:
Now I could just copy this code to a new editor.