Sponsored Content
Top Forums Shell Programming and Scripting find file and print only contents with a hit by grep Post 302364394 by zaxxon on Friday 23rd of October 2009 01:35:17 AM
Old 10-23-2009
If your grep does not have -o etc. and this is regarding to your former post https://www.unix.com/shell-programmin...g-problem.html, you can also just slightly modify the line I already gave in the there to get only the matches in the files, not the complete files as output:

Code:
$> cat file1
eins
zwei
OCT
drei
vier
$> cat file2
16-SEP-2009 09:11:47 10.65.4.24
16-SEP-2009 09:11:47 10.3.4.11
30-SEP-2009 10:11:47 10.3.4.11
1-OCT-2009 10:11:47 10.65.4.24
6-OCT-2009 10:11:47 10.3.4.11
6-OCT-2009 12:31:01 10.3.4.11
16-OCT-2009 11:11:47 10.65.4.24
17-OCT-2009 11:11:47 10.65.4.24
18-OCT-2009 11:11:47 10.3.4.11
$> find . -type f -exec grep -l OCT {} \; | while read LINE; do awk -v l=$LINE '/OCT/ {print l":"$0}' $LINE; done
./file2:1-OCT-2009 10:11:47 10.65.4.24
./file2:6-OCT-2009 10:11:47 10.3.4.11
./file2:6-OCT-2009 12:31:01 10.3.4.11
./file2:16-OCT-2009 11:11:47 10.65.4.24
./file2:17-OCT-2009 11:11:47 10.65.4.24
./file2:18-OCT-2009 11:11:47 10.3.4.11
./file1:OCT

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies

2. Shell Programming and Scripting

awk - print file contents except regex

Hello, I have a file which has user information. Each user has 2 variables with the same name like Email: testuser1 Email: testuser1@test.com Email: testuser2 Email: testuser2@test.com My intention is to delete the ones without the '@' symbol. When I run this statement awk '/^Email:/&&!/@/'... (6 Replies)
Discussion started by: rmsagar
6 Replies

3. Shell Programming and Scripting

print contents of any file within some timeframe

Hi, Is there anyway to print contents of any file ( say log files that grow automatically) within some timeframe ( comparing with current time), say print contents of the added in: 1) last 2 hr 2) last 45 min 3) last 3 hrs 47 min (3 Replies)
Discussion started by: fed.linuxgossip
3 Replies

4. UNIX for Dummies Questions & Answers

find file grep it and print file name

i am trying to search a few hundred release note text files for a certain word. however when i use the below command i can find a file that contains it but i dont know the file name. how can i change this command to output the name of the file that grep was successful in? find builds -name... (4 Replies)
Discussion started by: borderblaster
4 Replies

5. Shell Programming and Scripting

Read contents of the file and print

AT ---------- 0 Elapsed: 00:00:00.02 SO ---------- 0 Elapsed: 00:00:00.01 SE ---------- 0 Elapsed: 00:00:00.01 CR ---------- (4 Replies)
Discussion started by: sandy1028
4 Replies

6. Shell Programming and Scripting

script to read the contents of a file and print

Hi, Need help in writing a script to read the contents of this file test Test 00a 00b 00c 00d 00e 00f where it need to read each line to give a display such as form meta from dev 00a , config=Striped; add dev 00b:00f to meta 00a Can any one help me in writing this script (2 Replies)
Discussion started by: praveen1516
2 Replies

7. UNIX for Dummies Questions & Answers

Print file name when running grep from within find

Solaris 10 When running grep from within find command (don't know the technical term for 'running from within' ) , find command returns only the line which contains the pattern. Is there any way to get the file name printed as well ? $ pwd /opt/testdir/anotherDir $ $ $ cat findme.txt... (3 Replies)
Discussion started by: omega3
3 Replies

8. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

9. Shell Programming and Scripting

How to grep and print the next and previous N lines after the hit

Hello, I know that gnu grep has option of -A and -B to extra previous and next lines. But I'm using HP UX and its grep does not support these options. BID="0/0/6/1/1.145.17.255.0.0.0" I need to search a file using $BID and get next 5 lines and previous 5 lines separately. Please... (1 Reply)
Discussion started by: reddyr
1 Replies

10. UNIX for Beginners Questions & Answers

Bash command to find a file and print contents

I need to find a file and print its contents I am trying but it is not working find -path /opt/app-root/src/.npm/_logs -type f -name "*.log" -print Version $ bash -version GNU bash, version 4.4.12(1)-release (x86_64-pc-msys) (1 Reply)
Discussion started by: SVRao19056
1 Replies
AFCAT(1)						      General Commands Manual							  AFCAT(1)

NAME
afcat - Output contents of an image file to stdout. SYNOPSIS
afcat [options] image [images] DESCRIPTION
affcat outputs the contents of an image file to stdout. Image files that are not raw but are recognized by AFF will be output in raw for- mat. Missing pages will not be padded, but the fact that they are missing will be noted on STDERR. The options are as follows: -s name Output the named segment, instead of the image data. This is a way to output metadata. -p nnn Just output page number nnn -S nnn Just output data sector number nnn. Sector #0 is the first sector. -q Quiet mode. Don't print to STDERR if a page is skipped because it is not present. -n Noisy mode. Tell when pages are skipped. -l List all the segment names, rather than outputing data. -L List Long. Prints segment names, lengths, and args. -d Debug mode. Print the page numbers to stderr as data goes to stdout. -b Output BADFALG for bad blocks (default is to output NULLs). -v Just print the version number and exit. -r offset:count Seek to the given byte offset and output count characters in each file; may be repeated. HISTORY
afcat first appeared in AFFLIB v1.00. AUTHOR
Simson Garfinkel <simsong@acm.org> User Manuals OCT 2008 AFCAT(1)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy