LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2013, 07:38 AM   #1
peacepanda
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Rep: Reputation: Disabled
Question Help with writing a script!!!!


Hi All,
I am trying to write a script which would do following Job.

1.)Search for multiple patterns in a directory
Eg patterns "abc" and "xyz" in directory "/dsd/audit".

This pattern I want to search in files of certain pattern suppose the files are of pattern "date_BBBCC"

I want to search the pattern in both zip files as well as non zip files

i.e in .Z files as well as regular files.

Also I want to search for the pattern for only files of certain date ranges.

Please let me know how do I approch to write this script or how can this be done
This I am trying to do in AIX 5.3.

Thanks for all the help.

Regards,
Ajjit
 
Old 09-19-2013, 07:47 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I don't know AIX

I would start by reading the man pages for find and grep, along with that of the shell you use
 
1 members found this post helpful.
Old 09-20-2013, 08:28 AM   #3
Pap
Member
 
Registered: May 2011
Distribution: Salix 14.1 GNU/Linux, 64-bit
Posts: 70

Rep: Reputation: 29
You should use grep for manual searching in files. The simplest use is
Code:
grep "date_BBBCC" foo.txt
which will list all the lines in the file "foo.txt", where the pattern "date_BBBCC" appears. You can do custom searches using listing commands like tail or most. For example,
Code:
tail -n 100 foo.txt|grep -c "date_BBBCC"
will tell you how many times the pattern "date_BBBCC" is found in the last 100 lines of the file "foo.txt", without listing them (just counting them.)
To search in gzipped files, use something like
Code:
gzip -cd foo.gz|grep "date_BBBCC"
There are many more ways to use grep to do what exactly you want, too many to list them all here; man page for grep is the first step.

If, however, you just want to do such custom searches, and making a script for all that is not what you really need, I suggest installing Worker (must be available in most distros.) It is actually a very lightweight file manager (and very old-fashioned in looks) that can do all you are asking for very easily, and show results in a convenient way.

Last edited by Pap; 09-20-2013 at 08:36 AM.
 
1 members found this post helpful.
Old 09-20-2013, 09:11 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,685

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by peacepanda View Post
Hi All,
I am trying to write a script which would do following Job.

1.)Search for multiple patterns in a directory Eg patterns "abc" and "xyz" in directory "/dsd/audit". This pattern I want to search in files of certain pattern suppose the files are of pattern "date_BBBCC"

I want to search the pattern in both zip files as well as non zip files i.e in .Z files as well as regular files. Also I want to search for the pattern for only files of certain date ranges.

Please let me know how do I approch to write this script or how can this be done
This I am trying to do in AIX 5.3.
You've posted several questions like this, and have been told before that we will NOT write your scripts for you:
http://www.linuxquestions.org/questi...al-4175438242/

..and have been pointed to bash scripting tutorials. We will be very glad to HELP you, so post what YOU have written/tried first, and tell us where you're stuck. Otherwise, read the scripting tutorials, and break the tasks you're trying to accomplish down into commands you can type in. grep is obviously one, since you're searching for a pattern, as is find for finding files in a certain date range.

You posted questions like this more than a year ago...during that time, shouldn't you have learned something about scripting?
 
1 members found this post helpful.
Old 09-22-2013, 02:11 PM   #5
peacepanda
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Original Poster
Rep: Reputation: Disabled
Thanks for the responses

Tbone
Thanks for telling me the same thing what u have told me year long.Do u think ur answer had helped me then or now.But thanks again for pointing me to the same tutorials.
 
Old 09-22-2013, 02:32 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,685

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by peacepanda View Post
Tbone
Thanks for telling me the same thing what u have told me year long.Do u think ur answer had helped me then or now.But thanks again for pointing me to the same tutorials.
Spell out your words. And unless YOU actually start reading/following the tutorials, and writing your own scripts, you will NEVER learn how to do it for yourself. Coming back and asking for handouts over and over isn't a good thing.

If you're too lazy to learn, then PAY SOMEONE to write scripts for you. Don't ask people to do your work for free.
 
2 members found this post helpful.
Old 09-22-2013, 03:37 PM   #7
Pap
Member
 
Registered: May 2011
Distribution: Salix 14.1 GNU/Linux, 64-bit
Posts: 70

Rep: Reputation: 29
Quote:
Originally Posted by peacepanda View Post
Tbone
Thanks for telling me the same thing what u have told me year long.Do u think ur answer had helped me then or now.But thanks again for pointing me to the same tutorials.
Sounds like what people call "trolling" nowadays. So, you admit you had the same questions... ONE year ago. And, let me guess, in the meantime you didn't bother reading the tutorials people pointed to you. A simple glance on them would be enough to start writing your own scripts. Even the few examples I posted earlier should be enough to get started as well. But apparently you just want (actually demand) someone to do the whole job to you, as if we are your servants. This, I can assure you, it won't happen.

We talk again if an when you have a script and you got stuck somewhere, when you first try and come back with specific questions... which, let me guess, it will never happen.
 
3 members found this post helpful.
  


Reply

Tags
scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Writing a script that will open a terminal window and run another script jeffery1 Linux - General 5 02-16-2013 03:30 PM
Need help writing script VorlonShadow Linux - General 15 06-02-2010 07:39 AM
Need help writing script Rustylinux SUSE / openSUSE 1 12-05-2006 10:05 AM
Help writing script Geminias Linux - Newbie 9 08-02-2006 09:45 PM
Help Writing a script. teeth44 Programming 2 10-14-2003 12:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration