Enumere la salida en forma de tabla

Enumere la salida en forma de tabla

tengo una salida de

Student Name: abc
Roll Num: 123

Student Name: xyz
Roll Num: 124

y necesito imprimir en el siguiente formato

Student Name     Roll Num
abc              123
xyz              124

¿Alguien puede ayudarme con comandos simples de Linux?

Respuesta1

awkPor supuesto, no es la única herramienta en la caja de herramientas. Aquí estáMolineroen acción:

%mlr --ixtab --ips : --opprint cat << FIN
Nombre del estudiante: abc
Número de rollo: 123

Nombre del estudiante: xyz
Número de rollo: 124

FIN
Nombre del estudiante Número de lista
 abc 123
 xyz 124
%

Estás realizando una conversión del formato XTAB ( -ixtab) al formato PPRINT ( -opprint).

Respuesta2

Elige tu opción:

$ awk -v RS= -F': |\n' -v OFS='\t' 'NR==1{print $1, $3} {print $2, $4}' file
Student Name    Roll Num
abc     123
xyz     124

$ awk -v RS= -F': |\n' -v OFS='\t' 'NR==1{print $1, $3} {print $2, $4}' file | column -s$'\t' -t
Student Name  Roll Num
abc           123
xyz           124

$ awk -v RS= -F': |\n' -v fmt='%-13s %-13s\n' 'NR==1{printf fmt, $1, $3} {printf fmt, $2, $4}' file
Student Name  Roll Num
abc           123
xyz           124

Respuesta3

Method1

awk 'BEGIN{print "Student Name";RS="Student Name:"}{print $1}' p.txt| awk '$0 !~ /^$/' >student.txt
awk   'RS="Roll Num"{print $2}' p.txt|sed '/Name/,/^$/d'| awk 'BEGIN {print "Roll Num"}{print $0}' > roll.txt


paste student.txt  roll.txt


output

Student Name     Roll Num
abc              123
xyz              124



 Method2

awk 'BEGIN{print "Student Name"}{if($1 ~ /Student/){print $3}}' p.txt > student.txt

awk 'BEGIN{print "Roll Num"}{if($1 ~ /Roll/){print $3}}' p.txt > roll.txt

paste student.txt  roll.txt


output

Student Name     Roll Num
abc              123
xyz              124

información relacionada