glob.glob() function in python scripting

A forum for general discussion of the Python programming language.

glob.glob() function in python scripting

Postby sivakumar » Thu Apr 10, 2014 7:12 am

I need some suggestion on glob function.

I am trying to write a python program to grep some specific files in a particular directory.
In the directory i have some files like below
in this directory i need to grep onlu my hostname files, my host name is abc, so the output should be

I have written the program as below

Code: Select all
import os, re, tty, sys, termios, glob, subprocess, time, socket
userhome = os.getenv( 'HOME')
host = socket.gethostname()
host_files = glob.glob(-------) ##here I got struck.

Please help me how to fill glob.glob line in the above coding
Last edited by stranac on Thu Apr 10, 2014 9:12 am, edited 1 time in total.
Reason: First post lock.
Posts: 1
Joined: Thu Apr 10, 2014 7:01 am

Re: glob.glob() function in python scripting

Postby metulburr » Thu Apr 10, 2014 9:16 am

Code: Select all
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
User avatar
Posts: 1947
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: glob.glob() function in python scripting

Postby stranac » Thu Apr 10, 2014 9:20 am

To match the files starting with "abc.", use the pattern "abc.*"
The special characters you can use are listed in the fnmatch docs.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1595
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests