Obtaining File information based on String Search

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Obtaining File information based on String Search
# 1  
Old 10-04-2013
Lightbulb Obtaining File information based on String Search

Is there a single Command in Unix to get the following Information when searching for files containing one or more strings in a Unix Directory (including sub directories within it) :
  • 1) Complete filename ( path and filename)
  • 2) Owner of the file
  • 3) Size of the file
  • 4) Last Modified date
  • 5) Line in the File containing the strings.


Last edited by pchegoor; 10-04-2013 at 08:14 PM..
# 2  
Old 10-04-2013
Points 1,2,3 are quite easy:
echo -e "User\tSize\tFile"
list=$(find|sed s,^\./,\ ,g|sed s,^\.,\ ,g)
for found in $list;do ls -l "$found"|awk '{print $3" "$5" "$9}';done

Hope this helps

Last edited by sea; 10-04-2013 at 08:58 PM.. Reason: no need to sort find'ings...
# 3  
Old 10-04-2013
Did you want the whole matching line(s), or just the line numbers?

Assuming the latter:
find $(srchpath) -type f | while read filename
   matching=$(grep -nE "${srch}" "${filename}")
   if [[ $? -eq 0 ]]
      linenumbers=$(echo "${matching}" | awk -F: '{printf $1 OFS} END {printf "\n"}')
      printf "%s %s\n" "${filename}" "${linenumbers}"

Someplace before the printf you could pull the remaining info out using stat or ls (as in sea's solution) into another variable.
# 4  
Old 10-05-2013
You may want to try also (given stat is on your system)
grep -ErnH "$srch" * |
awk -F: '{("stat -c\"%U %s %y\" \""$1"\"") | getline x
          split (x,y," ")
          print $1,y[1],y[2],y[3],$2}

Last edited by RudiC; 10-05-2013 at 11:19 AM..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find string based on pattern and search for its corresponding rows in column

Experts, Need your support for this awk script. we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file Need to grep row whose string contains 9K from column 1. When found... (6 Replies)
Discussion started by: as7951
6 Replies

2. UNIX for Beginners Questions & Answers

Search for the information at file

I'm having few question. i'm have a input file. Other information CONNECTIONS "BP-COLLECTOR" J6.4 "BP-TEST".4; +5VS C34.1 U21.1; DEV_I2C_SDA J6.6 R4.1 U18.1; DEVICES "BP-TEST" 1."BP-LED_ANODE" (8 Replies)
Discussion started by: kttan
8 Replies

3. UNIX for Beginners Questions & Answers

Get information from one files, based on data from other file

Hello. I am trying to get some info from log file. I have fileA , which contains all the country prefixes (the file contains one column and "n" rows ). And i have fileB, which contains huge data of phone numbers (the file contains one column and "n" rows). What i want to do is, to count... (7 Replies)
Discussion started by: dragonfly85
7 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

6. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

7. Shell Programming and Scripting

Extracting data between tags based on search string from unix file

Input file is on Linux box and the input file has data in just one line with 1699741696 characters. Sample Input: <xxx><document coll="uspatfull" version="0"><CMSdoc>xxxantivirus</CMSdoc><tag1>1</tag1></document><document coll="uspatfull"... (5 Replies)
Discussion started by: gaya
5 Replies

8. Shell Programming and Scripting

using sed to conditionally extract stanzas of a file based on a search string

Dear All, I have a file with the syntax below (composed of several <log ..... </log> stanzas) I need to search this file for a number e.g. 2348022225919, and if it is found in a stanza, copy the whole stanza/section (<log .... </log>) to another output file. The numbers to search for are... (0 Replies)
Discussion started by: aitayemi
0 Replies

9. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies

10. Programming

Obtaining Process information on AIX

I have written a program to collect some performance metrics on and AIX box, but I'm having difficultly getting the process information. I'm lead to believe that I'm not getting the correct information because I'm trying to run the program on AIX 5.1 (5100-03), but I'm not convinced as the... (0 Replies)
Discussion started by: StuBob
0 Replies
Login or Register to Ask a Question