A FIND and
GREP Combination
Using find and grep together: To find all files with target pattern in any given directory use the command: % find [target_dir] -exec grep -l 'target' {} \; This uses the find fuction with the grep function to specify absolute path to all files with the target pattern in them. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- I want to searh a record in the table. But I don't want to display out the entire row or column record. What I want to display is only a single row or column record. I have try grep ann file-name what should I add so I can display the row 4 record that I have. The following command display the column 4 of the forst line of the input file containing 'ann' : awk '/ann/ {print $4;exit}' input_file -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Is there any method that u know using grep instead of using awk to the example above. I'm using "grep ann inputfile" and it show all the entire row and not the record on column 4. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The short answer is - no. The grep utility is a line orientated
utility. You can use grep to find/print the line but you then
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There is a way of doing it.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This is my example: name age number (not list in the file)
My question is that now I know how to cut the column already but when I cut it I want to use grep to display out the age that less than 50, how should use grep to search age that less than 50. I have try using grep [:digit:] < 50 file but I fail to do this. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- cut -d\ -f2 example |grep -E "^[0-9]$|^[0-4][0-9]$" -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Of course, that takes advantage of 50 being a multiple
of 10. <54 would be a bit hairy'er.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Sorry for posting againt but still not very understand, how about I using grep to compare column 3 record (exp: < 25.50) and display record at column 1 and 3 that match the requirement using grep. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- "compare column 3 record" or column 2 ??
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- To display all rows in test.dat where the value in the
second column is less than 50:
As others have pointed out, grep is a tool for pattern filtering, not output manipulation.
Related:
Unix Forum - Do you have a UNIX Question? Unix Books :-
Return to : Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|