Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

search and export on AIX IBM

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)...
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

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
Avatar of Pau Lo
Pau Lo

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pau Lo

ASKER

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)?
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.
Avatar of Pau Lo

ASKER

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?
Avatar of Pau Lo

ASKER

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.
"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.
Avatar of Pau Lo

ASKER

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?
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......"
Avatar of Pau Lo

ASKER

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?
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.