mardi 24 février 2015

How to cut python output in rows and coloumn

Hi All i have written below program to take output of linux process



import subprocess
def backupOperation():
p = subprocess.Popen(["ls","-la"], stdout=subprocess.PIPE)
output, err = p.communicate()
print(output)

backupOperation()


if i print output its output is as shown below



-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
drwx------. 3 root root 24 Dec 21 15:14 .dbus
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Desktop
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Documents
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Down loads
drwx------. 2 root root 22 Dec 21 17:07 .elinks
-rw-------. 1 root root 16 Dec 21 15:21 .esd_auth
drwx------. 2 root root 79 Dec 21 16:42 .gnupg
-rw-------. 1 root root 1240 Feb 21 20:19 .ICEauthority
-rw-r--r--. 1 root root 1142 Dec 21 15:15 initial-setup-ks.cfg
drwx------. 3 root root 18 Dec 21 15:21 .local
drwxr-xr-x. 4 root root 37 Dec 21 16:53 .mozilla
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Music
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Pictures
drwxr-----. 3 root root 18 Dec 21 15:49 .pki
-rw-r--r-- 1 root root 172 Feb 24 22:44 process.py
-rw-------. 1 root root 10 Dec 21 17:48 .psql_history
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Public
-rw-------. 1 root root 1024 Dec 21 16:43 .rnd
drwx------ 2 root root 24 Feb 22 00:12 .ssh
drwx------. 3 root root 4096 Dec 21 16:44 ssl-build
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Templates
drwxr-xr-x. 2 root root 6 Dec 21 15:21 Videos
-rw------- 1 root root 6994 Feb 24 22:44 .viminfo


all i want is to cut first coloumn of the out put as i do using awk like awk '{print $1}' Here i want to do this using python but i do not find any suitable string function doing this.Can this be achieved using python or i have to use shell for such operations.


Aucun commentaire:

Enregistrer un commentaire