shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Transformar linhas em coluna


From: Julio C. Neves
Subject: Re: [shell-script] Transformar linhas em coluna
Date: Wed, 17 Feb 2016 16:57:13 -0200

É tanto rWindows que dá até medo de mexer neste arquivo... ;)
Usando o processo KISS:

1 - Listando com os cabeçalhos:
$ grep -E '(Product Name|Product ID|Product Key)' ARQ | xargs -L 3

Product Name : Internet Explorer Product ID : 00333-OEM-9999999-11111 Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Product Name : Windows 7 Professional Product ID : 00333-OEM-9999999-00000 Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Product Name : Internet Explorer Product ID : 00333-OEM-9999999-11111 Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Product Name : Windows 8.1 Pro Product ID : 00333-OEM-9999999-00000 Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

2 - Listando somente os dados
$ grep -E '(Product Name|Product ID|Product Key)' ARQ | cut -f2 -d: | xargs -L 3

Internet Explorer 00333-OEM-9999999-11111 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Windows 7 Professional 00333-OEM-9999999-00000 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Internet Explorer 00333-OEM-9999999-11111 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Windows 8.1 Pro 00333-OEM-9999999-00000 XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

3 - Formatando a saída
$ grep -E '(Product Name|Product ID|Product Key)' ARQ | tr ' ' ^ | cut -f2 -d: | xargs -L 3 printf '%-25s %-25s %20s\n' | tr ^ ' '

 Internet Explorer         00333-OEM-9999999-11111   XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
 Windows 7 Professional    00333-OEM-9999999-00000   XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
 Internet Explorer         00333-OEM-9999999-11111   XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
 Windows 8.1 Pro           00333-OEM-9999999-00000   XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Abcs,
Julio
@juliobash

P
róximos cursos de Shell
Cidade         Local Período
Rio de Janeiro EDX 05-06/03 e 12-13/03 (Sábados e Domingos)
São Paulo 4Linux 11/04 a 15/04
Dou treinamento de Shell em qualquer cidade.
Para mais detalhes, me mande um e-mail.


Em 17 de fevereiro de 2016 09:12, Verilton Lopes address@hidden [shell-script] <address@hidden> escreveu:
 

Caros, bom dia.

Preciso da ajuda de vocês.

Tenho o seguinte arquivo texto:
==================================================
Product Name      : Internet Explorer
Product ID        : 00333-OEM-9999999-11111
Product Key       : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Installation Folder :
Service Pack      :
Computer Name     : LAB-WKS
Modified Time     : 28/01/2014 16:44:23
==================================================

==================================================
Product Name      : Windows 7 Professional
Product ID        : 00333-OEM-9999999-00000
Product Key       : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Installation Folder : C:\Windows
Service Pack      :
Computer Name     : LAB-WKS
Modified Time     : 20/02/2015 17:30:01
==================================================

Consigo filtrar o que desejo (Nome do PC, softwares e chaves) usando o awk, veja abaixo:

Product Name : Internet Explorer
Product ID : 00333-OEM-9999999-11111
Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Computer Name : LAB-WKS
Product Name : Windows 8.1 Pro
Product ID : 00333-OEM-9999999-00000
Product Key : XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Computer Name : LAB-WKS

Contudo, não consigo colocar estes dados em linha.
Ex.:
<Computer Name> <Product Name> <Product Key> <Product Name> <Product Key> <Product ID>

LAB-WKS Internet Explorer XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Windows 7 Professional XXXXX-XXXXX-XXXXX-XXXXX-XXXXX 00333-OEM-9999999-00000


Alguém pode ajudar?

--
Verilton Lopes.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]