Solved

search and export on AIX IBM

Posted on 2014-02-14
12
379 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

867 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

22 Experts available now in Live!

Get 1:1 Help Now