?
Solved

search and export on AIX IBM

Posted on 2014-02-14
12
Medium Priority
?
386 Views
Last Modified: 2014-02-18
is there any way on AIX IBM to run a searh query where text appears within a file, and export the actual search hits to a csv/txt file (including file name, path, and the autopreview where the search term appears)...
0
Comment
Question by:pma111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39858699
Please post samples of the input file and of the desired output data, so we might be able to understand what you're after.

wmp
0
 
LVL 3

Author Comment

by:pma111
ID: 39858706
there is no input file, the search text could appear in any file of any format. And output report would just need list the filename and path for all files found that include the search text.

i.e. search for all files that contain "experts" across all drives on the server. And then a way of exporting the list of search hits to  a file.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39858736
All drives? You mean all directories/mountpoints starting from / ? I assume this will take a long time, but here you go:

Including matching text:

grep -R "expert" / 2>/dev/null > /tmp/experts.txt

Filenames only:

grep -Rl "expert" / 2>/dev/null > /tmp/experts.txt
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 3

Author Comment

by:pma111
ID: 39858745
albeit not an AIX admin myself, could you provide some recommendations on area of a file system to focus on, or areas you could exclude. This will have been a purposelly created file by a user.

Can you provide a sample of the experts.txt so I can see the types of search results it would return? And also, can you limit it to where the search term is in the text of the file, and not neccesarily the filename. or does the above example cover both (i.e. where the search phrase lives in the filename or the text within the file)?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39858794
I think you should focus on the place where the home directories of your users live (usually /home), and also /var and /tmp.
Besides that, you should of course include all your homegrown filesystems where your users have write access to.

grep -r "expert" /home /var /tmp /myuserfs1
grep -rl "expert" /home /var /tmp /myuserfs1

The first version will return something like

/home/pma111/myfile1:   there are experts of all flavors at EE for
/home/pma111/myfile1: Each of those experts has an own area of
/home/pma111/myfile2: An expert is a person with a high degree of skill in or knowledge of

The second version will just return:

/home/pma111/myfile1
/home/pma111/myfile2

grep can show the number(s) of the line(s) with matching text. Use the "-n" flag for this (does not work with the second  "filenames only" version above).

grep -rn "expert" /home /var /tmp /myuserfs1

This will look like this:

/home/pma111/myfile1:12:   there are experts of all flavors at EE for
/home/pma111/myfile1: 15:Each of those experts has an own area of
/home/pma111/myfile2:1: An expert is a person with a high degree of skill in or knowledge of

grep can also show the number of matches per file (-c flag). However, this is not useable with "-r" (recursive), because filenames without matches will also be displayed, with count = 0

Finally, grep can display matches without filenames (not possible in recursive mode), and it can perform a word search (-w) which means that "expert" will match in the above examples, while "experts" will not.

grep alone cannot limit its search to selected areas of a file, unfortunately.
0
 
LVL 3

Author Comment

by:pma111
ID: 39858797
Thanks, I assume

grep -r "expert" /home /var /tmp /myuserfs1

is something I need to tweak, or is "myusersfs1" a default AIX folder, equivalent to windows c:\users?
0
 
LVL 3

Author Comment

by:pma111
ID: 39858804
and is there anyway to build in wild card type searching, i..e. if you want to search for words beginning with, say "an*" but would be interested in words such as and, ant, answer etc.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39858814
"myuserfs1" is not AIX standard. I invented this name to indicate a homegrown FS.

The equivalent to C:\users is "/home" on AIX. "/u" on AIX is a link to /home, so the content is the same.

You don't need wildcards for the searches you posted.

grep "an" will automatically find and, ant, answer etc. , but also man, woman, handyman etc.
0
 
LVL 3

Author Comment

by:pma111
ID: 39858819
ok thanks, but is there no way to search all homegrown FS, is there no top level folder to search them all in one command, as opposed (presumably) one search term for every homegrown FS. and also one search for all home directories and howgrown FS?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39858842
There is usually no top level folder above homegrown filesystems. You could of course have designed your directory structure like that, but virtually nobody does it, from my experience.

The logical volumes of all AIX filesystems start with "hd...". so if you didn't name your logical volumes similarly this might be a hint at your own filesystems.

df -P |awk '!/Filesystem/&&!/\dev\/hd/&&!/\/proc/ {print $NF}'

will produce a list of your homemade mountpoints, if and only if you didn't name your homemade logical volumes "/dev/hd......"
0
 
LVL 3

Author Comment

by:pma111
ID: 39858858
so basically it is one search per homegrown file system on the server? and I assume the home directories will be within one of these file systems?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39858870
1) You can specify more than one starting point for a recursive search, see my examples.

2) Per standard the home directories are under /home which is an AIX  filesystem (not homegrown). But this can be changed, if desired - sometimes people do it that way, but not very often.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question