grep pipe filename print issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep pipe filename print issue
# 1  
Old 08-02-2011
Question grep pipe filename print issue

Code:
uname -a
SunOS mypc 5.10 Generic_141414-07 sun4v sparc SUNW,SPARC-Enterprise-T2000

Code:
uname -a
SunOS mypc 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220


Code:
find . -name "*.cer" -exec keytool -v -list -printcert -file {} \; | grep -i "Aug 03"
Valid from: Mon Jan 29 00:00:00 GMT 1996 until: Thu Aug 03 00:59:59 BST 2028
Valid from: Mon Jan 29 00:00:00 GMT 1996 until: Thu Aug 03 00:59:59 BST 2028

As you can see in the output below the filename in which the desired string was found is not printed.

I need the respective filename printed along with the greped output.

Kindly help.

Last edited by radoulov; 08-02-2011 at 09:33 AM.. Reason: Code tags.
# 2  
Old 08-02-2011
Something like this may work (untested):

Code:
find . -name '*.cer' -exec bash -c '
  fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i 'Aug 03' &&
      printf '%s\n' "$fn"
  ' inline {} \;

# 3  
Old 08-02-2011
Try This:


Code:
find . -name "*.cer" -exec ksh -c 'echo -n $1" ";keytool -v -list -printcert -file $1' {} {} \; | grep -i "Aug 03"

p.s. Please replace 'ksh' with whatever shell you are using.

Last edited by radoulov; 08-02-2011 at 02:52 PM.. Reason: Code tags, please!
# 4  
Old 08-02-2011
Error

Quote:
Originally Posted by radoulov
Something like this may work (untested):

Code:
find . -name '*.cer' -exec bash -c '
  fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i 'Aug 03' &&
      printf '%s\n' "$fn"
  ' inline {} \;

Code:
more "checkcert.sh"

find . -name '*.cer' -exec bash -c '
  fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i 'Aug 03' &&
      printf '%s\n' "$fn"
  ' inline {} \;

bash# ./checkcert.sh

No Output

Does not yield any output.

---------- Post updated at 02:03 PM ---------- Previous update was at 02:01 PM ----------

Quote:
Originally Posted by a20786
Try This:


Code:
find . -name "*.cer" -exec ksh -c 'echo -n $1" ";keytool -v -list -printcert -file $1' {} {} \; | grep -i "Aug 03"

p.s. Please replace 'ksh' with whatever shell you are using.

Code:
find . -name "*.cer" -exec ksh -c 'echo -n $1" ";keytool -v -list -printcert -file $1' {} {} \; | grep -i "Aug 03"

Valid from: Mon Jan 29 00:00:00 GMT 1996 until: Thu Aug 03 00:59:59 BST 2028
Valid from: Mon Jan 29 00:00:00 GMT 1996 until: Thu Aug 03 00:59:59 BST 2028

Did not help.
# 5  
Old 08-02-2011
Actually, it should be:

Code:
find . -name '*.cer' -exec bash -c '
  fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i "Aug 03" &&
      printf "%s\n" "$fn"
  ' inline {} \;

If it still doesn't return any output, post the output of the following command:

Code:
find . -name '*.cer' -exec bash -c '
  set -xv; fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i "Aug 03" &&
      printf "%s\n" "$fn"
  ' inline {} \;

This User Gave Thanks to radoulov For This Post:
# 6  
Old 08-03-2011
Question

[QUOTE=radoulov;302543980]Actually, it should be:

Code:
find . -name '*.cer' -exec bash -c '
  fn=$1
  keytool -v -list -printcert -file "$fn" |
    fgrep -i "Aug 03" &&
      printf "%s\n" "$fn"
  ' inline {} \;

This works !!!

However, how can we tweak the above to achieve this

Search for '*.jks' along with '*.cer' and
for *.cer use keytool -v -list -printcert -file "$fn"
and
for *.jks use keytool -v -list -keystore "$fn"

and the grep for "Aug 03" remains the same for both *.cer and *.jks.

Again, thankful for your help.
# 7  
Old 08-03-2011
Try this:

Code:
find . \( -name '*.cer' -o -name '*.jks' \) -exec bash -c '
  fn=$1
  case $fn in
    ( *.cer ) _opt="-printcert -file" ;;
    ( *.jks ) _opt="-keystore"        ;;
  esac	
  keytool -v -list $_opt "$fn" |
    fgrep -i "Aug 03" &&
      printf "%s\n" "$fn"
  ' inline {} \;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Space in input filename with pipe

Hello, Normally below script works, could you please comment out what could be the reason of failure if there are spaces in input filename: script.sh #!/bin/bash cd /home/hts/.hts/tvh/ file="$1 $2 $3 $4" read -d $'\x04' name < "$file" /usr/bin/ffmpeg -i ""$name"" -vcodec copy -preset... (1 Reply)
Discussion started by: baris35
1 Replies

2. UNIX for Dummies Questions & Answers

Print/cut/grep/sed/ date yyyymmdd on the filename only.

I have this filename "RBD_EXTRACT_a3468_d20131118.tar.gz" and I would like print out the "yyyymmdd" only. I use this command below, but if different command like cut or print....etc. Thanks ls RBD_EXTRACT* | sed 's/.*\(........\).tar.gz$/\1/' > test.txt (9 Replies)
Discussion started by: dotran
9 Replies

3. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

4. Shell Programming and Scripting

How to pipe a filename that includes a date?

How do I pipe the output of something to a filename that includes the date, in a specific date format? Here's the goal. Output a script to a file periodically during the day: ./script.sh >>logname_yyyy-mm-dd.logAnd when the next day comes, it starts logging to a new filename because the date... (2 Replies)
Discussion started by: nbsparks
2 Replies

5. Shell Programming and Scripting

Diff between grep .* file name and grep '.*' filename

Hi, Can anyone let me know what is difference between grep .* foo.c grep '.*' foo.c I am not able to understand what is exact difference. Thanks in advance (2 Replies)
Discussion started by: SasDutta
2 Replies

6. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

7. Shell Programming and Scripting

Filename pattern match and appending pipe

Hi, I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records. I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each... (3 Replies)
Discussion started by: nss280
3 Replies

8. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

9. AIX

Removing a filename which has special characters passed from a pipe with xargs

Hi, On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories. Having said that I am more curious to know how this can be done. an sample... (3 Replies)
Discussion started by: jerardfjay
3 Replies

10. Shell Programming and Scripting

using grep and print filename

Hi, I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files. I have alot files such that a.txt, b.txt,c.txt...etc. If I found a certain character, I would print that particular filename. I... (5 Replies)
Discussion started by: ahjiefreak
5 Replies
Login or Register to Ask a Question