Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Search directory for string and print file name Post 302997656 by SIMMS7400 on Wednesday 17th of May 2017 07:41:25 PM
Old 05-17-2017
Search directory for string and print file name

Good Evening Folks -

I have a need to search a specific directory and ALL sub-directories for the following string:

Code:
Data Load Updated

If this string is found, I need to print content from the line directory above it between [] symbols, as well as the file name where it is found.

Here is a sample file content:

Code:
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1013166)
Received Command [Import] from user [admin@Native Directory] using [FCSTCD.rul]

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003040)
Parallel dataload enabled: [1] block prepare threads, [1] block write threads.

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003037)
Data Load Updated [648] cells

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003053)
Data Load Elapsed Time with [FCSTCD.rul] : [0.011] seconds

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP///175440/Info(1013210)
User [admin@Native Directory] set active on database [Fin_Plan]

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP///176308/Info(1042059)
Connected from [::1]

[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/176308/Info(1013091)
Received Command [Calculate] from user [admin@Native Directory]

Therefore, if this string is found in 'Application1.log' for instance, the results file should contain:

Code:
Application1.log
Tue Mar 07 15:08:31 2017

Is this possible?

Thank you!

---------- Post updated at 07:41 PM ---------- Previous update was at 06:36 PM ----------

I came up with this solution and it seems to be working fine:

Code:
find /home/oracle/Hyperion_Batch/Scripts/Batch -type f | xargs awk '{A[NR]=$0}/Data Load Updated/{print A[NR-1]}'>>output.txt

If this is not the correct approach, please let me know.

Last edited by SIMMS7400; 05-17-2017 at 07:48 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

2. Shell Programming and Scripting

Search a string and print the rest of line

Hi Guys, I need to search a string and print the rest of the lines... input: 8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n output: 00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n Actually i don even need the first "00".. any suggestions is appreciated..... (13 Replies)
Discussion started by: mac4rfree
13 Replies

3. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

4. Shell Programming and Scripting

Print #of lines after search string in a big file

I have a command which prints #lines after and before the search string in the huge file nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=10 s="STRING1" FILE The file is 5 gig big. It works great and prints 10 lines after the lines which contains search string in... (8 Replies)
Discussion started by: prash184u
8 Replies

5. Shell Programming and Scripting

search a word and print specific string using awk

Hi, I have list of directory paths in a variable and i want to delete those dirs and if dir does not exist then search that string and get the correct path from xml file after that delete the correct directory. i tried to use grep and it prints the entire line from the search.once i get the entire... (7 Replies)
Discussion started by: dragon.1431
7 Replies

6. Shell Programming and Scripting

search-word-print-specific-string

Hi, Our input xml looks like: <doc> <str name="account_id">1111</str> <str name="prd_id">DHEP155EK</str> </doc> - <doc> <str name="account_id">6666</str> <str name="prd_id">394531662</str> </doc> - <doc> <str name="account_id">6666</str> <str... (1 Reply)
Discussion started by: Jassz
1 Replies

7. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

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

9. Shell Programming and Scripting

Script to search every file in a directory and print last few lines

Hi everyone, I need to write a script to search a directory, output the name of a file to an ouput file and print the last few lines of the files to the output file such that I would have something like this: FILE1: LINE LINE LINE FILE2: LINE LINE LINE FILE3: LINE LINE LINE... (2 Replies)
Discussion started by: mojoman
2 Replies

10. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 07:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy