Skip to content

Commit

Permalink
General Upload - 2021/02/11
Browse files Browse the repository at this point in the history
  • Loading branch information
mxnt10 committed Feb 11, 2021
0 parents commit 143eb96
Show file tree
Hide file tree
Showing 7 changed files with 1,352 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.17)
project(refine)

set(CMAKE_CXX_STANDARD 20)

add_executable(refine main.cpp file_utils.h)
18 changes: 18 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ChangeLog
All notable changes to this project will be documented in this file.
Todas as mudanças notáveis ​​neste projeto serão documentadas neste arquivo.


## [ 1.0 ] - 2021-02-08 ##################################################

### Added / Adicionado
- Added parameter -f for read the first lines of the files.
- Added parameter -l for read the last lines of the files.
- Added parameter -a for read a line from a file.
- Added parameter -d and -s for read the specific lines of the files.
- Added parameter -h for view help information.
- The Parameter -e0 -t0 -a0 and -d0 has the same result as -e -t -a -d,
but without enumerating the lines.
###

##########################################################################
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Refine - v1.0
*Reads specific lines of text documents.*
<br/>

The *refine* command was created to read specific lines of text files. This command, usually does the service that *head* and *tail* do. However, it has some extra parameters that are not present in other commands in a natural way.

The interest of this project is to create a command that facilitates the search for specific lines in files, without having to resort to *pipes* or huge codes to obtain the desired output.
<br/><br/>

For example, I want the clean output of line 10:
```sh
$ cat -n file.txt | grep -w "10" | cut -d$'\t' -f2-
```
<br/>

If there is a more efficient way, it will not be different from that. Another example is to display lines 10 to 20:
```sh
$ head -20 file.txt | tail -11
```
<br/>

It is short, but if the file has 15 lines instead of 20, this combination will not do this control and will display 11 lines and not 6, which would be 10 to 15.
<br/><br/>

### Parameters:
<br/>

The *refine* it has the following syntax:
```
$ refine [options] file.txt
```
<br/>

The *refine* it has a series of parameters. See the follow:
```sh
-f: To read the first lines of the files.
-f0: The same effect, but cleanly.
-l: To read the last lines of the files.
-l0: The same effect, but cleanly.
-a: To read a line from a text file.
-a0: The same effect, but cleanly.
-d: To read the specific lines of the files. This one delimits the start of the reading.
-d0: The same effect, but cleanly.
-s: Select the limit of specific lines. Must be used after -d or -d0.
-h: To view help information.
```
<br/>

### Comparation and Use:
<br>

The use of *refine* is very simple. Let's start with the basic commands. How was said, this command has the functions of *head* and *tail*, but with some improvements, as can be seen folow:
```sh
$ head -5 LICENSE
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
```
```sh
$ refine -f 5 LICENSE

LICENSE:
1: GNU GENERAL PUBLIC LICENSE
2: Version 3, 29 June 2007
3:
4: Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5: Everyone is permitted to copy and distribute verbatim copies
```
```sh
$ refine -f0 5 LICENSE

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
```
<br/>

Now, compared to the *tail*. As you can see the empty line also comes into the equation. The line is empty, but it exists, so it must be counted. However, it will be visible only in -l and as an extra line:
```sh
$ tail -5 LICENSE
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
```
```sh
$ refine -l 5 LICENSE

LICENSE:
670: into proprietary programs. If your program is a subroutine library, you
671: may consider it more useful to permit linking proprietary applications with
672: the library. If this is what you want to do, use the GNU Lesser General
673: Public License instead of this License. But first, please read
674: <https://www.gnu.org/licenses/why-not-lgpl.html>.
675:
```
```sh
$ refine -l0 5 LICENSE

into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
```
<br/>

Now comes the part that makes sense of the command existance. Let's compare the output of specific numbers of lines, which, in the example, will be listed lines in 26 to 30, as can be seen folow:
```sh
$ head -30 LICENSE | tail -5
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
```
```sh
$ refine -d 26 -s 30 LICENSE

LICENSE:
26: want it, that you can change the software or use pieces of it in new
27: free programs, and that you know you can do these things.
28:
29: To protect your rights, we need to prevent others from denying you
30: these rights or asking you to surrender the rights. Therefore, you have
```
```sh
$ refine -d0 26 -s 30 LICENSE

want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
```
<br/>

Now, to close with golden key, let's analyze the code used to read only a specific line, as in the following example:
```sh
$ cat -n LICENSE | grep -w " 10"
10 The GNU General Public License is a free, copyleft license for
446 10. Automatic Licensing of Downstream Recipients.
```
```sh
$ cat -n LICENSE | grep -w " 10" | cut -d$'\t' -f2-
The GNU General Public License is a free, copyleft license for
10. Automatic Licensing of Downstream Recipients.
```
```sh
$ refine -a 10 LICENSE

LICENSE:
The GNU General Public License is a free, copyleft license for
```
```sh
$ refine -a0 10 LICENSE
The GNU General Public License is a free, copyleft license for
```
<br/>

The result dispenses with comments. So, to conclude, here is a command alternative to facilitate the search for specific lines in files.

--> NOTE: The commands were thought to be used separately, so nothing of "-fl".
<br/>

### GNU General Public License:

This repository has scripts that were created to be free software.<br/>
Therefore, they can be distributed and / or modified within the terms of the *GNU General Public License*.

>[General Public License](https://pt.wikipedia.org/wiki/GNU_General_Public_License)
>
>Free Software Foundation (FSF) Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
<br/><br/>
### Comments:

In case of bugs, execution problems or packages construction, constructive criticism, among others, please submit a message to one of the contacts below.
<br/><br/>

### Contact:

Autor: Mauricio Ferrari

E-Mail: *m10ferrari1200@gmail.com*

Telegram: *@maurixnovatrento*
168 changes: 168 additions & 0 deletions README_PT-BR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Refine - v1.0 - PT-BR
*Ler linhas específicas de documentos de texto.*
<br/>

O comando refine foi criado para ler linhas específicas de arquivos de texto. Este comando, geralmente faz o serviço que o *head* e o *tail* fazem. Porém, ele possui alguns parâmetros extras que não estão presentes em outros comandos de forma natural.

O interesse desse projeto é criar um comando que facilite a busca por linhas específicas em arquivos, sem precisar recorrer a *pipes* ou códigos enormes para obter a saída desejada.
<br/><br/>

Por exemplo, eu quero a saída limpa da linha 10:
```sh
$ cat -n file.txt | grep -w "10" | cut -d$'\t' -f2-
```
<br/>

Se houver um modo mais eficiente, ele não será diferente disso. Outro Exemplo, é exibir as linhas de 10 a 20:
```sh
$ head -20 file.txt | tail -11
```
<br/>

Até que é curto, mas se o arquivo tem 15 linhas ao invés de 20, essa combinação não fará esse controle e exibirá 11 linhas e não 6, que seria de 10 a 15.
<br/><br/>

### Parametros:
<br/>

O *refine* possui a seguinte Sintaxe:
```
$ refine [options] file.txt
```
<br/>

O refine possui uma série de parâmetros. Veja a seguir:
```sh
-f: Para ler as primeiras linhas de arquivos de texto.
-f0: O mesmo efeito, só que de forma limpa.
-l: Para ler as últimas linhas de arquivos de texto.
-l0: O mesmo efeito, só que de forma limpa.
-a: Para ler uma linha de um arquivo de texto.
-a0: O mesmo efeito, só que de forma limpa.
-d: Para ler um número específico de linhas de arquivos de texto. Esse delimita o início da listagem.
-d0: O mesmo efeito, só que de forma limpa.
-s: Seleciona o limite de linhas específicas. Deve ser usado após -d ou -d0.
-h: Para visualizar as informações de ajuda.
```
<br/>

### Comparação e Uso:
<br>

O uso do *refine* é bem simples. Vamos começar com os comandos básicos. Como foi dito, esse comando possui as funções do *head* e do *tail*, só que com algumas melhorias, como pode ser visto a seguir:
```sh
$ head -5 LICENSE
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
```
```sh
$ refine -f 5 LICENSE

LICENSE:
1: GNU GENERAL PUBLIC LICENSE
2: Version 3, 29 June 2007
3:
4: Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5: Everyone is permitted to copy and distribute verbatim copies
```
```sh
$ refine -f0 5 LICENSE

GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
```
<br/>

Agora, comparando com o *tail*. Como vocês podem ver a linha vazia também entra na equação. a linha está vazia, mas ela existe, portanto deve ser contada. Porém, ela será visível apenas em -l e como uma linha extra:
```sh
$ tail -5 LICENSE
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
```
```sh
$ refine -l 5 LICENSE

LICENSE:
670: into proprietary programs. If your program is a subroutine library, you
671: may consider it more useful to permit linking proprietary applications with
672: the library. If this is what you want to do, use the GNU Lesser General
673: Public License instead of this License. But first, please read
674: <https://www.gnu.org/licenses/why-not-lgpl.html>.
675:
```
```sh
$ refine -l0 5 LICENSE

into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
```
<br/>

Agora chegou a parte que faz sentido a existência do comando. Vamos comparar a saída de números específicos de linhas que, no exemplo, será listada as linhas de 26 a 30, como pode ser visto a seguir:
```sh
$ head -30 LICENSE | tail -5
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
```
```sh
$ refine -d 26 -s 30 LICENSE

LICENSE:
26: want it, that you can change the software or use pieces of it in new
27: free programs, and that you know you can do these things.
28:
29: To protect your rights, we need to prevent others from denying you
30: these rights or asking you to surrender the rights. Therefore, you have
```
```sh
$ refine -d0 26 -s 30 LICENSE

want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
```
<br/>

Agora, para fechar com chave de ouro, vamos analizar aquele código usado para fazer a leitura de apenas uma linha específica, como no exemplo a seguir:
```sh
$ cat -n LICENSE | grep -w " 10"
10 The GNU General Public License is a free, copyleft license for
446 10. Automatic Licensing of Downstream Recipients.
```
```sh
$ cat -n LICENSE | grep -w " 10" | cut -d$'\t' -f2-
The GNU General Public License is a free, copyleft license for
10. Automatic Licensing of Downstream Recipients.
```
```sh
$ refine -a 10 LICENSE

LICENSE:
The GNU General Public License is a free, copyleft license for
```
```sh
$ refine -a0 10 LICENSE
The GNU General Public License is a free, copyleft license for
```
<br/>

O resultado dispensa comentários. Então para concluir, aqui está uma alternativa de comando para facilitar na busca por linhas específicas em arquivos.

--> Nota: Os comandos foram pensados para serem usados separadamente, então nada de "-fl".
Loading

0 comments on commit 143eb96

Please sign in to comment.