Replace certain text in lines with each line another file - awk

I have a text file with text of this order;
str/4
<</Contents(100 cups)/(Date)
Colour red
<</Contents(080 bowls)/(Date)
Status used
Pack team
<</Contents(200 John)/(Date)
School house
And another text file with a list of words in the order;
Tree house
Colon format
Same variable
Now the question is, how do I search or match the text between "Contents(" and ")" in each line, ie. 100 cups, 080 bowls, 200 John and replacementreplace it with corresponding lines from my second file? . The final result should look like;
str/4
<</Contents(Tree house)/(Date)
Colour red
<</Contents(Colon format)/(Date)
Status used
Pack team
<</Contents(Same variable)/(Date)
School house

Related

I would like to MOVE just one line in Vim

yy and p should copy and paste 1 line of text.
But I have to go back and delete the original line.
:2,5m10
should move lines from 2 to 5 to line 10. however I need to enable :set number
to see what lines I am moving
I would like to move just 1 line of text, sort of like yy+p and not use :2,3m10
to move just one line.
Is there something like mm+p ?
so it copies the current line into buffer and deletes the line and you p paste it where you want ?
:3m . moves line 3 to your current line.
Above line does the function I want. Can I set a key mapping so
that "mm" replaces ":3m." ? I find it easier to type. TIA
What you're describing is the default behaviour when using dd -it deletes a
line into the buffer and p will paste it.
So dd and p works.
If you're new to vim, then it might seem a little strange that 'yanking' (with
y) and 'deleting' (with d) both copy to the buffer, given the 'cut', 'copy'
and 'paste' behaviours of most other editors.
You can read more about it with :help change.txt and in particular :help registers.
Also, since you say you need to enable :set number, I wonder if you've come
across :set relativenumber? This is very useful - in the example below, the
numbers would look this way if the your cursor was on the line with
'demonstrate':
3 This is just
2 a small
1 example to
0 demonstrate
1 how relative
2 numbers can
3 be useful
Thus if you wanted to move the line 'a small' below the line with 'numbers
can', you could use the relative line numbers to know that 2k would put the
cursor on the line you want, where you'd hit dd, then you'd have this
situation (the deleted line is now in the buffer:
1 This is just
0 example to
1 demonstrate
2 how relative
3 numbers can
4 be useful
Then you can do 3j to move to the 'numbers can' line, and hit p. So
relative numbers are a nice way to move quickly to lines you can see. Also,
just for completeness, you can use relative numbers in a similar way on the
command line::-2m+3 (although I know this isn't what you're after). You can
even set both relative number and set number at the same time, in which case
it's like in the example above, only you have the absolute line number
displayed on the current line instead of a zero.

Vimium: something like "f" for input fields?

In Vimium, is there something like f for input fields? E.g. in a form with 10 input fields, I directly want to jump to the 5th, instead of only gi and tabbing through. Is that possible using Vimium?
Yes, as in many shortcuts in vim you can prefix a command with a number. I.e. to jump to the 5th field you type 5gi.
Other vim style examples (It isn't related to vimium. I included it only to illustrate the approach):
3dd delete 3 lines
2j go up 2 lines
5p paste the buffer 5 times

How to select specific data from text file in VB?

I am making an Arduino weather station and I am outputting the data to a simple text file. But I want to make a like a year log of the highest and lowest temps. So my question is how can I select only the data between some symbols and then use it in VISUAL BASIC...For example my text file contains this string:"[29.11.2015 AT: 19:19:43] MR t. C:| 22.18 |Out t. C:| 7.36 |Aqu. H20 t. C:| 23.12 |Light(MR):| 1.63 | Door in MR:CLOSED!" and as you can see all the data is surrounded by these "|", can I make vb to get only this data and then compare it to previous one?
Take a look at TextFieldParser. Your delimiter will be the "|".

How to find the same words in two different text files and print those lines using bash?

I have two text files. One contain just one column of words. Hundreds of words. Just one word in every line. The second one contain a lot of columns a row.
I need to find the words from first text file which are in the second text file and print the entire line from second text file where this word is, using awk, grep or other command line program. For example:
Text file #1:
car
house
notebook
Text file #2:
32233: FTD laptop
24342: TGD car
2424: jdj notebook
Output:
24342: TGD car
2424: jdj notebook
try this:
grep -Fwf file1 file2

Trouble with opening files in python

I was trying to write a program where I can upload a file that has first and last names in it and create a new file with the first letter of each first name followed by the last name.
The file that I created is a textfile and the lines would be like this:
firstname1 lastname1 (for example, john smith)
firstname2 lastname2 (for example jane jones)
firstname 3 lastname3 (for example jane doe)
etc...
I want to create a file that would look like this:
jsmith
jjones
jdoe
The issue that I am getting is that when I open the file in python it gives me all of these weird unwanted characters before getting to the actual text of the file. The book I am using to learn from doesn't say anything about this which is why i am posting here.
For example when I upload the file and run the following command:
newfile=open("example.file.rtf","r")
for i in newfile:
print(i)
I get this:
{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
\f0\fs24 \cf0 name 1\
name 2\
name 3 \
name 4 \
The actual text that I wrote in the textfile was just this:
name 1
name 2
name 3
name 4
Why is this happening? Why wouldn't it just show the plain text? If I can't get it to do that, how can I get around this issue for when I run loops through the file.
You are writing the file in RTF ("Rich Text") format, which is not plain text. Those "weird unwanted characters" are being written there by your editor. Use a plain text editor like Notepad to create your file, or explicitly save it as plain text.