sed: search 5 lines text anche change only first and last - text

I need to find in a long list of files 5 lines like:
TEXT 1
Text 2
Text 3
Text 4
Text 5
and change it with
NEW TEXT 1
Text 2
Text 3
Text 4
NEW TEXT 5
I need to that the command will match any text for the 3 lines "Text 2/3/4" and keep them in the result.
Example 2:
Initial text:
TEXT 1
Pippo
Pluto
Paperino
Text 5
Result:
NEW TEXT 1 XXXX
Pippo
Pluto
Paperino
NEW Text 5 XXXX
The matching strings are not the first and last line of text.
I tried this command, but I don't know how to copy
the text in substitution text:
sed 'N;N;N;N;N;TEXT 1.*Text 5/NEW TEXT 1.*Text 5' filename
Thanks

Related

Excel table to text

I have an excel table formatted(with header row included just for reference) like so:
1
2
3
4
5
1
2
3
4
5
5
2
2
5
2
2
-
2
I would like it formatted as text like so:
522 522 -2
Whenever I paste into word and convert to text it prints a space in between cells that are adjacent like this (underline as space):
5_2_2_ 5_2_2 _ -_2
I also tried pasting into other text editors and VScode without success.
I have several lines of this data and it's actually longer than the example so it's fairly cumbersome to manually delete the spaces. I'm wondering if there's a way to do this in excel/word.

Excel - How to Find All Possible Combinations For 4 Columns - (No VBA) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a simple 4 column table below:
Column A Column B Column C Column D
HEAD BODY PARAGRAPH IMAGE
Headline 1 Body Text 1 Paragraph 1 Image 1
Headline 2 Body Text 2 Paragraph 2 Image 2
Headline 3 Body Text 3 Paragraph 3 Image 3
What I want is to have, all the combinations I could get out of those columns, which I can illustrate as:
Column F Column G Column H Column I
HEAD BODY PARAGRAPH IMAGE
Headline 1 Body Text 1 Paragraph 1 Image 1
Headline 1 Body Text 1 Paragraph 1 Image 2
Headline 1 Body Text 1 Paragraph 1 Image 3
Headline 2 Body Text 2 Paragraph 2 Image 1
Headline 2 Body Text 2 Paragraph 2 Image 2
Headline 2 Body Text 2 Paragraph 2 Image 3
Headline 3 Body Text 3 Paragraph 3 Image 1
Headline 3 Body Text 3 Paragraph 3 Image 2
Headline 3 Body Text 3 Paragraph 3 Image 3
etc.
Basically I want the same answer as - Excel – Multiple Columns, Different Combinations but only for 4 columns and not 3 and no VBA please.
This is possible if we think about everything as a 4 digit number, where in the example given because there are 3 options in each column, we would want a base 3 number. I am writing it up for 3, but it should be clear how to extend it. A little below, I'll indicate how to handle different numbers of options in each column.
Suppose your data appears in A1:D4. I chose to leave column E blank so I could read things easily. F1 got the following formula:
=mid(base(row()-1,3,4),1,1)
which construes the row number - 1 (1-1=0, here) as a 4 digit base 3 number and takes the first digit.
G1 has the 2nd digit: =mid(base(row()-1,3,4),2,1)
H1 has =mid(base(row()-1,3,4),3,1)
and I1 has =mid(base(row()-1,3,4),4,1)
Then select F1:I1 and drag down through row 81 (which will have 2 2 2 2).
J1 gets =index(A$2:A$4,1+F1), which gets dragged right through M1.
Then drag J1:M1 down through row 81, and you have all the ones you want.
[later you can hide columns that were work columns or build their formulas into more inscrutable ones.]
Now suppose you want to be able to handle the case where there are different numbers of options in each category. Let's assume n is the largest number of options. I'll illustrate for n=3, but again it should be generalizable.
Assuming the possibilities sit in columns J:M, In N1, I placed =if(counta(J1:M1)=4,join(",",J1:M1),""), and dragged that all the way down to keep all the things that have one thing in each category present, but the phantom entries totally blank. In O1 I put =sort(N1:N,1,false) to send the blanks to the bottom, and then for the rows until the blanks, in P1 and dragged on down place =split(O1,",").
There are some possible generalizations here where when I used numbers but you could use counts of entries in your columns, but I think this should get you pretty far. There is also a limitation in this approach that you cannot have more than 36 of any choice.

I need to read line from two text files and import to a new file by shell

Example: file one content in file is:
5
4
3
2
1
file two:
five
four
three
two
one
I want to read from two file inputs to new file by shell script:
new file:
5 five
4 four
3 three
2 two
1 one
Read man paste:
<bash> paste file1 file2 > newfile
<bash> cat newfile
5 five
4 four
3 three
2 two
1 one
With pr :
$ pr -mts file1 file2 > outputfile
5 five
4 four
3 three
2 two
1 one

Making 'column' ignore lines with fewer tokens than max for pretty display

I am trying to view a csv file. The csv files contains 2 types of lines:
lines with say 15 entries (numbers or strings) separated using commas. The number of entries can vary by file, but will be fixed for all such lines in a single file.
lines containing just one large string and no commas
I was trying to use column -s, -t for easy viewing on the command line. The problem is for lines containing just one entry, column thinks of it as a member of the first column. This string is big and causes the first column to be pretty big. I am looking for a way to tell column to not format rows which have just 1 entry and just print them as is. Is this achievable using column or some other utility? I tried using tr ',' '\t', but that didn't align things nicely like column.
Example file:
asdfasgjfsgadjfasdgjafsdgfkjasgdfkjasgkdasdfagjdghfa
this,is,just,a,siiiiiiiiimple,sample,file
1,2,3,4,5,6,7
wish_column_had_some_more_options
this,is,just,a,siiiiiiiiimple,sample,file
7,6,5,4,3,2,1
column output:
asdfasgjfsgadjfasdgjafsdgfkjasgdfkjasgkdasdfagjdghfa
this is just a siiiiiiiiimple sample file
1 2 3 4 5 6 7
wish_column_had_some_more_options
this is just a siiiiiiiiimple sample file
7 6 5 4 3 2 1
tr output:
asdfasgjfsgadjfasdgjafsdgfkjasgdfkjasgkdasdfagjdghfa
this is just a siiiiiiiiimple sample file
1 2 3 4 5 6 7
wish_column_had_some_more_options
this is just a siiiiiiiiimple sample file
7 6 5 4 3 2 1

VIM append a sequence of number at the end of each line

I'm totally new to vim and I know what magical things vim can do. My requirement is to append a sequence of numbers at the end of each line and I saw somebody did that before in front of me. It's just that I don't have enough time to search for the correct command, so I think post a question here should be a faster way since I'm running out of time. Sorry for being a noob but seems this is the only way I can come up with.
So the sample file content is like
1 Afghanistan
2 Albania
3 Algeria
4 American
5 Andorra
6 Angola
7 Anguilla
8 Antarctica
a list of countries, imagine it is a database table and each column is separated with tab. I already figured out a way to append tab to the end of each line, but now the problem is to add a number at the end of each line as well, and the number for each line is exactly same with its id(the first number)
I somehow think that it should be done with visual mode, but please tell me a working solution if you know. Any help is highly appreciated.
Best Regards,
Hai Lang
Open your file in vim. Press ESC if not in escape mode.
write this :%s/$/\=line('.')/
This will append the sequence of numbers at the end of each line. To add numbers in the begining do
:%s/^/\=line('.')/
Input:
1 Afghanistan
2 Albania
3 Algeria
4 American
5 Andorra
6 Angola
7 Anguilla
8 Antarctica
Keystrokes:
:%s!^\(\d\+\).*!&\t\1<CR>
Output:
1 Afghanistan 1
2 Albania 2
3 Algeria 3
4 American 4
5 Andorra 5
6 Angola 6
7 Anguilla 7
8 Antarctica 8
Par : 20
Explanation:
: : start the command
% : on all lines
s : subsititute
! : start of pattern
^ : start of line
\( : start of group
\d : digit
\+ : one or more
\) : end of group
. : any character
* : any number of those
! : end of pattern
& : replace with - whole pattern
\t : a tab
\1 : first matched group
Carriage-return : execute
You could use recordings, which are enabled by q followed by a letter, which is the bookmark for that recording.
E.g.
In normal mode go to the first line and type:
qe
^
y<space>
$
p
q (to end the recording)
Now type #e to play the recording from letter e or 20#e, which repeats #e 20 times.
You can play around with the recordings like this. Maybe also record a j, in normal mode so it takes you to the next line.

Resources