Solved

search and export on AIX IBM

Posted on 2014-02-14
12
378 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
  • 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 500 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now