Find and replace variable text in Textwrangler - replace

I am looking for a way to replace variable text in large text file in TextWrangler.
Here is an example of text that I am starting with:
144: FTLF8529P3BCV-CS
22492: TRS2200SN-000C
24524: SFBR-5780APZ-CS2
26538: FTLF1428P2BNV-CS
30916: TRS7250SN-S103
And I want to replace it into following:
FTLF8529P3BCV-CS
TRS2200SN-000C
SFBR-5780APZ-CS2
FTLF1428P2BNV-CS
TRS7250SN-S103
Is there a find and replace option that will allow me to do this?
I tried inbuilt grep function, but it does not seem to be working correctly for me. The original text that I am trying to modify is slightly different then above.
It looks like this:
untitled text 16:144:Vendor PN FTLF8529P3BCV-CS
untitled text 16:22492: Vendor PN TRS2200SN-000C
untitled text 16:24524: Vendor PN SFBR-5780APZ-CS2
untitled text 16:26538: Vendor PN FTLF1428P2BNV-CS
untitled text 16:30916: Vendor PN TRS7250SN-S103
So I tried grep find on "untitled text 16**Vendor PN " but that did not work. I got syntax error.
Here is the full error message:
The search cannot proceed, because of a syntax error in the Grep pattern: nothing to repeat (application error code: 12209).
I tried this, and it works:
untitled text 16:[0-9]*: Vendor PN [ ]*\
Thanks!

Go to text wrangler and under the search tab, choose Multi File Search. You will notice that a checkbox called Grep is probably checked. Uncheck that box and it should work.

Related

Is it possible to format the colour of parts of my git branch name inside the prompt?

In my .zshrc file I have the following lines that parse my current git branch and display it in the terminal, the .zshrc file looks like this:
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_} > '
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '(%b)'
So my terminal ends up looking like this:
me in ~/repos/myrepo (feat/MYISSUE-123/fix-the-broken-stuff) >
I would like to modify the script above so MYISSUE-123 has a different colour to the rest of the branch name.
How can I do that?
Try this ... change precmd to:
precmd() {
vcs_info
psvar=(${(s:/:)vcs_info_msg_0_})
# in case there are more than three components:
psvar[3]=${(j:/:)psvar[3,-1]}
}
Make sure precmd() is being called prior to each prompt display by adding it to the hook:
autoload -Uz add-zsh-hook
add-zsh-hook precmd precmd
And change PROMPT to:
PROMPT='%n in ${PWD/#$HOME/~} %1v/%F{red}%2v%f/%3v > '
There are some notes about psvar in this answer: https://stackoverflow.com/a/64094551/9307265.
The (s) and (j) parameter expansion flags are documented in the zshexpn man page.
Please let me know if there are any issues.

regex ansible lineinfile subsection

I am fairly new to ansible and have been solving the following problem with a shell script, but the proper way I believe is to use the lineinfile module, just not sure how to accomplish this.
Let's say I have a file with the following text in it.
<cpu>
<alarm>
active = yes
</alarm>
</cpu>
<disk>
<alarm>
active = yes
<fixed>
<#>
active = yes
description = File system /
<inode_error>
active = yes
threshold = 2
message = InodeError
</inode_error>
</#>
<#boot>
active = yes
description = File system /boot
percent = yes
<error>
active = yes
threshold = 5
message = DiskError
</error>
</#boot>
</fixed>
</alarm>
</disk>
I want to make sure the following section is set correctly.
<disk><alarm><fixed><#boot><error>"threshold = 2"</error></#boot></fixed></alarm></disk>
is there a way to only (modify/make sure exists) that line, normally this file is much larger with many more sections, but I erased some so the question is readable.
Update: Modifying this as it is not valid XML and the XML module will not parse the file correctly.
Thanks!
lineinfile scans file per line, so you can't define complex multiline regexp for context definition.
replace module support multiline regexp.
If you have threshold = X in the file and want to be sure it is set to specific value, you can use this regexp:
- replace:
path: ./test.txt
regexp: '(<disk>[\s\S]*<alarm>[\s\S]*<#boot>[\s\S]*<error>[\s\S]*)(threshold\s*=\s*\d+)([\s\S]*?<\/error>)'
replace: '\1threshold = 2\3'
It searches for line threshold\s*=\s*\d+ inside <disk>...<alarm>...<#boot>...<error>....
This code is idempotent – so if threshold = 2, then nothing is done.
But if there is no threshold = X string, it will fail. You should construct more complex regular expression for that case.
you could use the lineinfile module (http://docs.ansible.com/ansible/latest/lineinfile_module.html) where you could write a regex to modify/add the line and use the validate function to run a command to ensure that the xml file has the proper syntax.
If you are on Ansible 2.4 you can use the xml module (https://docs.ansible.com/ansible/2.4/xml_module.html) and use the attribute parameter to check if the xpath in xml file is set, like that:
- name: Read attribute value
xml:
path: /foo/bar.xml
xpath: /business/website/validxhtml
content: attribute
attribute: validatedon
register: xmlresp
regards

R: Countrycode package not supporting regex as the origin

I have a list of countries that i need to convert into standardized format (iso3c). Some have long names, others have 2 or 3 digit codes, and others do not display the whole country name like "Africa" instead of "South Africa". Ive done some research and come up to use countrycode package in R. However, when i tried to use "regex" R doesnt seem to recognize it. Im getting the error below:
> countrycode(data,"regex","iso3c", warn = TRUE)
Error in countrycode(data, "regex", "iso3c", :
Origin code not supported
Any other option I need to do?
Thanks!
You can view the README for the countrycode package here https://github.com/vincentarelbundock/countrycode, or you can pull up the help file in R by entering this into your R console ?countrycode::countrycode.
"regex" is not a valid 'origin' value (2nd argument in the countrycode() function). You must use one of "cowc", "cown", "eurostat", "fao", "fips105", "imf", "ioc", "iso2c", "iso3c", "iso3n", "p4_ccode", "p4_scode", "un", "wb", "wb_api2c", "wb_api3c", "wvs", "country.name", "country.name.de" (using latest version 0.19).
If you use either of the following 'origin' values, regex matching will be performed automatically: "country.name" or "country.name.de"
If you're using a custom dictionary with the new (as of version 0.19) custom_dict argument, you must set the origin_regex argument to TRUE for regex matching to occur.
In your example, this should do what you want:
countrycode(data, origin = "country.name", destination = "iso3c", warn = TRUE)

gvim not operator in substitute command

I've got a number of files that look like the one below:
HR0100001012010093001
EF0000120100930000000
HR0200001012010093001
EF0000120100930000000
HR0900001012010093001
EF000012010093000000
HR1000001012010093001
EF000012010093000000
HR1100001012010093001
text
EF000012010093000000
HR1200001012010093001
EF000012010093000000
HR1300001012010093001
EF000012010093000000
HR0100001012010093001
text
EF0000120100930000000
HR2000001012010093001
EF000012010093000000
HR2200001012010093001
EF000012010093000000
I'd like to strip off all the blocks starting with HRxx and ending with EF* except for those starting with HR01, i.e. I'd like to get the result below:
HR0100001012010093001
EF0000120100930000000
HR0100001012010093001
text
EF0000120100930000000
Using the command below:
:%s/HR01\_.\{-}EF.*$//g
I am able to DELETE the lines I'm searching for; as a final step, I'd like to use the "Not Operator" to reverse the result thus getting the lines I actually need. Unfortunately I don't understand how to do this.
Any help is greatly appreciated.
Thanks,
Francesco
Solution found:
%s/HR\(01\)\#!\_.\{-}EF.*$//g

Does Qt Linguist offer the ability to add new entries to the editable .ts file?

I didn't find a way to do this - only to edit the translations to the existing fields.
If there is no way to achieve this - how should this be done (somehow automatically, because right now I was manually adding
<message>
<source>x</source>
<translation>xx</translation>
</message>
blocks to my .ts file and I assume that's not the correct way.
No, that's not the correct way :) Use tr() in the code to mark strings for translation.
For example
label->setText( tr("Error") );
The you run lupdate for your project to extract them to a .ts. See here for more details.
Or do you need to translate strings that are not in the source code?
I just wrote a python script to insert new entries
into the .ts file for a homegrown parser using ElementTree. It doesnt make the code pretty
when it adds it, but I believe it works just fine (so far):
from xml.etree import ElementTree as ET
tree = ET.parse(infile)
doc = tree.getroot()
for e in tree.getiterator()
if e.tag == "context":
for child in e.getchildren():
if child.tag == "name" and child.text == target:
elem = ET.SubElement(e, "message")
src = ET.SubElement(elem, "source")
src.text = newtext
trans = ET.SubElement(elem, "translation")
trans.text = "THE_TRANSLATION"
tree.write(outfile)
Where infile is the .ts file, outfile may be the same as infile or different.
target is the context you are looking for to add a new message into,
and newtext is of course the new source text.