Notepad++ Combine Specific Line with second line - tabs

I'm trying to combine every line that starts with "Text" with the second line:
Text 1
Line 1
Line 2
Line 3
Line 4
Text 2
Line 1
Line 2
Line 3
Text 3
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Text 4
Line 1
Line 2
And I'd like it to look like this.
Text 1 Line 1
Line 2
Line 3
Line 4
Text 2 Line 1
Line 2
Line 3
Text 3 Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Text 4 Line 1
Line 2
I have managed to combine them but the issue is that it removes the number, so it ends up like "Text Line 1" instead of "Text 1 Line 1". I want to keep the tab space as well.

Ctrl+H
Find what: (^Text.*)\R
Replace with: $1
CHECK Wrap around
CHECK Regular expression
UNCHECK . matches newline
Replace all
Explanation:
( # start group 1
^ # beginning of line
Text # literally Text
.* # 0 or more any character but newline
) # end group
\R # any kind of linebreak
Replacement:
$1 # content of group 1
Screenshot (before):
Screenshot (after):

Related

how can I represent content of a file that there is on other file? [duplicate]

This question already has answers here:
Inner join on two text files
(5 answers)
Closed 2 years ago.
I have 2 big .csv file. I want to extract content of file 2 that there in file 1.
for example:
file1:
A1BG 1
NAT1 9
NAT2 10
SERPINA3 12
AAMP 14
AANAT 15
AARS1 16
file 2:
1 10422
1 10549
1 2232
1 23198
1 23352
1 284403
1 368
1 51035
1 80854
1 9923
2 10053
2 10376
2 10724
2 2026
2 2193
2 22976
2 23154
2 24138
2 2639
2 284207
2 285203
2 3337
2 3437
2 348
2 348
2 348
2 351
4 7689
output:
1 10422
1 10549
1 2232
1 23198
1 23352
1 284403
1 368
1 51035
1 80854
1 9923
it is my code:
awk 'NR==FNR{FS=" ";a[$2];next}{FS=" ";if ($1 in a) print $0}' <file1.csv <file2.csv >output.csv
but I have no output.
I believe you are simply looking for this solution in awk.
awk 'FNR==NR{a[$2];next} ($1 in a)' Input_file1 Input_file2
Explanation: Adding detailed explanation for above.
awk ' ##Starting awk program from here.
FNR==NR{ ##Checking condition FNR==NR which will be TRUE when Input_file1 is being read.
a[$2] ##Creating array a with index of 2nd field of current line.
next ##next will skip all further statements from here.
}
($1 in a) ##Checking condition if 1st field is present in array a then print that line from Input_file2
' Input_file1 Input_file2 ##Mentioning Input_file names here.
Let's look at your code:
awk 'NR==FNR{FS=" ";a[$2];next}{FS=" ";if ($1 in a) print $0}' <file1.csv <file2.csv >output.csv
You are redirecting input from 2 files. The shell can only have a single source of data for each file descriptor: the shell processes redirections from left to right as they are seen on the command line.
Try this:
awk 'NR==FNR' <file1.csv <file2.csv
and you'll probably be surprised at what awk considers the "first file".
awk is fully capable of reading files, you don't need the shell to do that:
awk 'NR==FNR' file1.csv file2.csv

Average Value Calculation

How to calculate the average value of a particular column in a text file with the help of Tcl Script ?
For example I have a text file containing 3 columns like:
1 2 3
4 5 6
5 9 7
3 2 8
And I want to do the average value calculation for Column 1 only; then How can I do it using Tcl script ?
Split by spaces to get the first column values
Create an empty list to store the values
Divide the sum by its length
someFile:
1 2 3
4 5 6
5 9 7
3 2 8
Hence:
values = [] # an empty list
with open(fileName, 'r') as f:
content = f.readlines()
content = [l.strip() for l in content if l.strip()] # to remove empty lines
for line in content:
values.append(int(line.split(" ")[0])) # convert str to int and append
print(sum(values) / float(len(values)))
OUTPUT:
3.25

Python 3.4 Reading csv files ignoring spaces before and after items

I'm trying to read different csv files with different delimiters. I have it working for space delimiters but it doesn't seem to properly read them if the have an extra space before or after the data.
The data is as follows:
Space Delimited Data
1 2 3
4 2 4
3 4 5
3 5 6
3 4 5
5 6 8
The last 3 rows would not be read properly (3 5 6, 3 4 5, 5 6 8) because of extra spaces before or after it. How can this be resolved?
My code is as follows:
def read(self, csv_file):
if self.delimiter == '':
with open(csv_file, newline='') as csvfile:
try:
dialect = csv.Sniffer().sniff(csvfile.read(), delimiters='space,;-\|\t\\')
csvfile.seek(0)
f = csv.reader(csvfile, dialect)
for row in f:
self.raw_data.append(row)

MYSQL INTO OUTFILE

I wrote a MySQL query for exporting data into text file.
Query runs successfully but result did not match my expectations.
I want to result without spacing between columns.
select
sample_export_record1_2013.*,
sample_export_record2_2013.*
from
sample_export_record1_2013
inner join
sample_export_record2_2013
INTO OUTFILE 'C:/Windows/temp/a20.txt'
FIELDS TERMINATED BY ""
LINES TERMINATED BY '\r\n'
STARTING BY '0'
Currently output is generated by this query like this :
01 181 2 0 P 5701 13.01.A.01 9664 0 94003048 94002596 0 3 20130101 20130106 000000001223 20130106 \N \N \N 2 1 258972658 9664 426407407 75 20050917 1 1 Reijtest \N 2 Reijtest \N o 1 2402LS \N 130 \N NL \N \N \N
I want the output without space between columns - just look like
0118120P570113.01.A.0196640940030489400259603201301012013010600000000122320130106\N\N\N212589726589664426407407752005091711 Reijtest\N2Reijtest\No12402LS\N130\NNL\N\N\N
Just use concat, SELECT CONCAT(rec1, rec2,rec3) as 'results' FROM...

Can an octave matrix hold strings and numbers together?

Is there a way that an Octave Matrix would hold Strings and numbers together?
I want to have a matrix of the fallowing type:
A=["A","B","C","D";1,2,3,4;2,3,4,5;3,4,5,6;4,5,6,7];
So that the matrix will look like:
A B C D
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
But when I try this I get:
ABCD
empty line
empty line
empty line
empty line
*empty line represents an empty line
And if I try to put strings that are more than 1 character in length, I get a number of columns mismatch error.
Is there a way to create a "mixed" octave matrix?
It sounds like you may be looking for a cell array.