vim : copy one entire column from one file to another file - vim

File #1:
F#1 A1 B1 C1
F#1 A2 B2 C2
F#1 A3 B3 C3
F#1 A4 B4 C4
F#1 A5 B5 C5
F#1 A6 B6 C6
File #2:
D1 E1 F1
D2 E2 F2
D3 E3 F3
D4 E4 F4
D5 E5 F5
D6 E6 F6
The wanted format in File#2:
F#1 D1 E1 F1
F#1 D2 E2 F2
F#1 D3 E3 F3
F#1 D4 E4 F4
F#1 D5 E5 F5
F#1 D6 E6 F6
In vim, how to copy the entire column (1st column in this example) from File #1 to File #2, as in the wanted format shown above? Note that, in reality, the file is very long.
Thank you.

Blockwise visual mode (CTRL-v) can help you achieving this (:help v for documentation).
The sequence of commands should be:
Go to the top-left corner.
Press CTRL-v. You should be in "VISUAL BLOCK" mode.
Press G - it will take you to the end of file.
Press l to mark the column (4 times in this case).
Press y to copy this column.
Open the second file (:e <second-filename>).
Go to the top left corner and press P to paste the column.

Related

Rolling available Calculation

What I think I am looking for is a rolling calculation, for example:
If A2 = F2:F4 Then subtract B2 from G2 and add C2 with result in D2. This would continue until it reaches the same part again like in rows 3,4,8,and 10. Once a part is repeated rather than looking at the column G I would like it to use the latest value in D.
A3 = F2:F4 subtract B3 from G3 and add C3 with result in D3 (20-5+0-15)
A4 = F2:F4 subtract B4 from D4 and add C4 with result in D4 (15-2+0-13)
A8 = F2:F4 subtract B8 from D8 and add C8 with result in D8 (13-8+7-12)
A10 = F2:F4 subtract B10 from D10 and add C10 with result in D10 (12-2+0-10)
Use VLOOKUP to return the correct start, and SUMIFS with dynamic range to do the subtraction and addition.
=VLOOKUP([#PART],Table3,2,FALSE)-SUMIFS($B$2:B2,$A$2:A2,[#PART])+SUMIFS($C$2:C2,$A$2:A2,[#PART])
Note: to use only structured references we need to introduce the volatile OFFSET:
=VLOOKUP([#PART],Table3,2,FALSE)-
SUMIFS(OFFSET(Table2[[#Headers],[QTY]],1,,ROW()-ROW(Table2[[#Headers],[QTY]])),OFFSET(Table2[[#Headers],[PART]],1,,ROW()-ROW(Table2[[#Headers],[PART]])),[#PART])+
SUMIFS(OFFSET(Table2[[#Headers],[DELIVERED QTY]],1,,ROW()-ROW(Table2[[#Headers],[DELIVERED QTY]])),OFFSET(Table2[[#Headers],[PART]],1,,ROW()-ROW(Table2[[#Headers],[PART]])),[#PART])

ForLoop VBA Coding Hardcoded values

Values Entered into Excel
A2 =4
A3 = 2500
C2= 15
D2= 30
E2 =35
F2= 40
Values to Populate:
I want to populate cells starting in cell C5 through Cells [C5 + (value in A2)] with the value in A3
So in this example C5 through F5 with the value in A3 (2500)
I want to populate cells starting in C6 through Cells [C6 + value in A2) with the corresponding cell values in (C2 + value in A2)
so in this example C6 = C2, D6 = D2, E6 = E2, F6 = F2
You only populate as many columns across as the number in A2

Concatenate and fill but not continuously

I have an excel sheet that I need to concatenate a couple of cells and then add a number. I want something like:
A1
A2
A3
A4
B1
B2
B3
A5
But instead, I get:
A1
A2
A3
A4
B5
B6
B7
A8
Is there a way to achieve what I want?
Thank you
Does this work for you? Added a helper column.

Deleting columns at regular intervals

I have a file with about 25000 columns and 3,000 lines. Now starting with column 4, I want to delete columns 3-5 at the interval of 8th column till the end.
Example:
The input file
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20
d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 d17 d18 d19 d20
Now I want the output file
c1 c2 c3 c4 c5 c9 c10 c11 c12 c13 c17 c18 c19 c20
d1 d2 d3 d4 d5 d9 d10 d11 d12 d13 d17 d18 d19 d20
I hope my question is not a confusing one. I know how to print at regular intervals but don't know how to solve this.
Simplest way is probably something like:
awk '{
printf "%s %s %s", $1, $2, $3
for (i=4; i<=NF; i++)
if ( ((i-3)%8) !~ /^[345]$/)
printf " %s", $i
print ""
}' file
c1 c2 c3 c4 c5 c9 c10 c11 c12 c13 c17 c18 c19 c20
d1 d2 d3 d4 d5 d9 d10 d11 d12 d13 d17 d18 d19 d20
It might need the math tweaked but hopefully you get the idea.

Column Summation of Cell Labels Excel

I have (sparse) data (in the first few cells for example where PA is A1 etc). The labels are fixed but the numbers need to be arbitrary\variable.
PA 5 8
RA 7 2.55 11 7.1
Pils 8 4.5 6.4
S\P 4 3.5 4.2 5.2 7.2
GH ED CW TR PH FL DG
Now I want to add up some of these entries. I want to add up all combinations under the following rule:
There should be one element from each row
There should be at most one element from each column
In this example I was able to do this by hand and the cells I want to add up (vertically) are as follows (this data is sitting in the four rows of cells below cells from B7 to AV7 inclusive):
B1 B1 B1 B1 B1 B1 B1 B1 B1 B1
C2 C2 C2 C2 C2 C2 D2 D2 D2 D2
F3 F3 F3 G3 G3 G3 C3 C3 C3 F3
D4 E4 H4 D4 F4 H4 E4 F4 H4 C4
******************************************************************************
B1 B1 B1 B1 B1 B1 B1 B1 B1 B1
D2 D2 D2 D2 D2 D2 F2 F2 F2 F2
F3 F3 G3 G3 G3 G3 C3 C3 C3 G3
E4 H4 C4 E4 F4 H4 D4 E4 H4 C4
******************************************************************************
B1 B1 B1 B1 B1 B1 B1 B1 B1 B1
F2 F2 F2 H2 H2 H2 H2 H2 H2 H2
G3 G3 G3 C3 C3 F3 F3 F3 G3 G3
D4 E4 H4 D4 E4 C4 D4 E4 C4 D4
******************************************************************************
B1 B1 D1 D1 D1 D1 D1 D1 D1 D1
H2 H2 C2 C2 C2 C2 F2 F2 F2 F2
G3 G3 F3 F3 G3 G3 C3 C3 G3 G3
E4 F4 E4 H4 F4 H4 E4 H4 C4 E4
******************************************************************************
D1 D1 D1 D1 D1 D1 D1
F2 H2 H2 H2 H2 H2 H2
G3 C3 F3 F3 G3 G3 G3
H4 E4 C4 E4 C4 E4 F4
******************************************************************************
Frankly I am stumped. I thought I could do stuff like =(=B7) and such but it isn't working. I would have tried some IF stuff but since the state space was so small I thought it might have been easier to write out all the combinations.
I need to send the worksheet to someone who will input the data and find the minimum of the 47 combinations.
Thank you for your time. I have a basic, working use of Excel.
The equivalent of what you are trying with =(=B7) would be =INDIRECT(B7). That is, get the value that B7 refers to.

Resources