Linux/Unix Shell Scripting - ayuda con shell

 
Vista:

ayuda con shell

Publicado por Sigfried (3 intervenciones) el 04/11/2004 22:22:02
Hola, mi pregunta es como puedo seleccionara de la salida de un comando la columna que yo quiera, por ejemplo si le doy "who" como resultado muestra varias columnas, entonces como puedo seleccionar solo aquellas columnas que yo quiera o cual es la instruccion, lo que quiero es obtener las columnas tal y como salen pero solo aquellas que yo quiera, si me pueden ayudar se los agradecere mucho, espero prontas respuestas bye.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

esta de parbulo

Publicado por [email protected] (7 intervenciones) el 23/11/2004 01:44:13
imagina que tecleas el comando ls -las, la salida seria mas o menos como:
<pre>
[rotosca@localhost rotosca]$ ls -las
total 1956
4 drwxr-xr-x 32 rotosca rotosca 4096 nov 22 18:42 ./
4 drwxr-xr-x 3 root root 4096 nov 17 20:41 ../
4 -rw------- 1 rotosca rotosca 1361 nov 19 22:29 .bash_history
4 -rw-r--r-- 1 rotosca rotosca 24 nov 12 16:59 .bash_logout
4 -rw-r--r-- 1 rotosca rotosca 191 nov 12 16:59 .bash_profile
4 -rw-r--r-- 1 rotosca rotosca 231 nov 12 16:59 .bashrc
4 drwxrwxr-x 3 rotosca rotosca 4096 nov 17 20:38 bittorrent/
24 -rw-rw-r-- 1 rotosca rotosca 21849 nov 4 19:45 blackbox-menu
4 drwxr-xr-x 3 rotosca rotosca 4096 nov 17 20:33 bombas/
4 drwxrwxr-x 4 rotosca rotosca 4096 nov 15 19:16 .cddb/
4 drwxrwxr-x 8 rotosca rotosca 4096 nov 15 18:57 cheli/
4 -rw-rw-r-- 1 rotosca rotosca 56 nov 22 18:35 .DCOPserver_localhost__0
0 lrwxrwxrwx 1 rotosca rotosca 38 nov 22 18:35 .DCOPserver_localhost_:0 -> /home/rotosca/.DCOPserver_localhost__0
4 -rwxr-xr-x 1 root root 12 nov 16 14:54 .desktop*
4 drwx------ 3 rotosca rotosca 4096 nov 16 19:28 Desktop/
4 -rw-r--r-- 1 root root 25 nov 16 14:54 .dmrc
4 drwxrwxr-x 4 rotosca rotosca 4096 nov 20 00:43 Documents/
24 -rw-rw-r-- 1 rotosca rotosca 22304 nov 1 00:16 dragon.gif
4 -rw-rw-r-- 1 rotosca rotosca 2123 oct 31 23:30 dragon.png
4 -rw-rw-r-- 1 rotosca rotosca 5 nov 14 19:13 .emacs-places
4 -rw------- 1 rotosca rotosca 16 nov 18 17:33 .esd_auth
4 -rw-rw-r-- 1 rotosca rotosca 3018 oct 21 19:58 es_splash.lyx
4 drwxrwxr-x 3 rotosca rotosca 4096 nov 15 18:57 fonts/
72 -rw-rw-r-- 1 rotosca rotosca 65597 nov 17 22:07 .fonts.cache-1
4 drwxrwxr-x 10 rotosca rotosca 4096 nov 17 18:54 Fotos/
4 drwx------ 4 rotosca rotosca 4096 nov 22 18:35 .gconf/
4 drwx------ 2 rotosca rotosca 4096 nov 22 18:35 .gconfd/
4 drwx------ 4 rotosca rotosca 4096 nov 17 20:48 .gnome/
4 drwx------ 4 rotosca rotosca 4096 nov 18 17:33 .gnome2/
4 drwx------ 2 rotosca rotosca 4096 nov 12 23:07 .gnome2_private/
4 drwxrwxr-x 5 rotosca rotosca 4096 nov 17 20:47 GNUstep/
4 -rw------- 1 rotosca rotosca 195 nov 22 18:35 .ICEauthority
12 -rw-r--r-- 1 rotosca rotosca 10871 oct 22 20:42 indic.pdf
4 drwxr-xr-x 2 rotosca rotosca 4096 nov 15 18:39 java-ejemplos/
4 drwxrwxr-x 2 rotosca rotosca 4096 nov 19 21:23 .kaffeine/
4 drwx------ 6 rotosca rotosca 4096 nov 12 23:08 .kde/
4 -rw-rw-r-- 1 rotosca rotosca 2083 nov 15 21:19 .mailcap
8 -rw-rw-r-- 1 rotosca rotosca 4675 sep 18 23:13 matlab.xpm
4 drwxr-xr-x 3 rotosca rotosca 4096 nov 12 23:08 .mcop/
4 -rw------- 1 rotosca rotosca 31 nov 22 18:25 .mcoprc
4 drwxr-xr-x 2 rotosca rotosca 4096 nov 14 21:35 .MdkOnline/
4 -rw-rw-r-- 1 rotosca rotosca 635 nov 15 21:19 .mime.types
4 drwxr-xr-x 3 rotosca rotosca 4096 nov 17 20:48 .nautilus/
4 -rw-rw-r-- 1 rotosca rotosca 16 nov 15 20:29 .net_applet
</pre>

con el comando de AWK puedes seleccionar campos de la siguiente manera:

ls -las | awk '{print $10, ", ", $2}'

aqui, la barra vertical | es una tuberia, es decir, la salida de un comando va a la entrada del otro, mandas llamar a awk y enseguida ejecutas un print, la salida seria algo asi como:

<pre>
[rotosca@localhost rotosca]$ ls -las | awk '{print $10, ", ", $2}'
, 1956
./ , drwxr-xr-x
../ , drwxr-xr-x
.bash_history , -rw-------
.bash_logout , -rw-r--r--
.bash_profile , -rw-r--r--
.bashrc , -rw-r--r--
bittorrent/ , drwxrwxr-x
blackbox-menu , -rw-rw-r--
bombas/ , drwxr-xr-x
.cddb/ , drwxrwxr-x
cheli/ , drwxrwxr-x
.DCOPserver_localhost__0 , -rw-rw-r--
.DCOPserver_localhost_:0 , lrwxrwxrwx
.desktop* , -rwxr-xr-x
Desktop/ , drwx------
.dmrc , -rw-r--r--
Documents/ , drwxrwxr-x
dragon.gif , -rw-rw-r--
dragon.png , -rw-rw-r--
.emacs-places , -rw-rw-r--
.esd_auth , -rw-------
es_splash.lyx , -rw-rw-r--
fonts/ , drwxrwxr-x
.fonts.cache-1 , -rw-rw-r--
Fotos/ , drwxrwxr-x
.gconf/ , drwx------
.gconfd/ , drwx------
.gnome/ , drwx------
.gnome2/ , drwx------
.gnome2_private/ , drwx------
GNUstep/ , drwxrwxr-x
.ICEauthority , -rw-------
indic.pdf , -rw-r--r--
java-ejemplos/ , drwxr-xr-x
.kaffeine/ , drwxrwxr-x
.kde/ , drwx------
.mailcap , -rw-rw-r--
matlab.xpm , -rw-rw-r--
.mcop/ , drwxr-xr-x
.mcoprc , -rw-------
.MdkOnline/ , drwxr-xr-x
.mime.types , -rw-rw-r--
.nautilus/ , drwxr-xr-x
.net_applet , -rw-rw-r--
.net_monitorrc* , -rwxrwxr-x
.oofficerc* , -rwxrwxr-x
.openoffice/ , drwxr-xr-x
public_html/ , drwxrwxr-x
.qt/ , drwxrwxr-x
scilab.pdf , -rw-r--r--
.screenrc , -rw-r--r--
.ssh/ , drwx------
.sversionrc , -rw-rw-r--
.thumbnails/ , drwx------
tmp/ , drwx------
.viminfo , -rw-------
vmware/ , drwxrwxr-x
.vmware/ , drwxrwxr-x
vmware.txt , -rw-r--r--
.Xauthority , -rw-------
.xine/ , drwxr-xr-x
.xplanet/ , drwxrwxr-x
.xsession-errors , -rw-------
</pre>

como te puedes dar cuenta $10 imprime la decima columna, ", ", genera una coma y un espacio y por ultimo $2 imprime la segunda columna.

Salu2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 50
Ha mantenido su posición en Linux/Unix Shell Scripting (en relación al último mes)
Gráfica de Linux/Unix Shell Scripting

RE:esta de parbulo

Publicado por caic (99 intervenciones) el 25/11/2004 05:43:16
otra opcion es el read:

who | while read uno dos tres ....
do
....
....
done

cada campo queda almacenado en las variables uno dos tres ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

eso no es de parbulo

Publicado por [email protected] (7 intervenciones) el 30/11/2004 05:14:43
Se te olvidaron algunas lineas, o se le seco la tinta a tu teclado.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ayuda con shell

Publicado por Eli (1 intervención) el 10/06/2009 18:15:37
Sos pendejo no sabes nada, me follare a tu madre
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar