bash script processing files with bad characters

1

I received a zip file with a folder structure that include parenthesis. I've worked through two processes at the cli and now merge them into a script

The first searches through the file structure for specific files correcting the parenthesis then pipes to tshark to process. my output using sed works at the stoud but the pipe tshark doesn't like the path I'm throwing.

find <path> -iname *.cap |sed 's/(/\\(/' |sed 's/)/\\)/'

takes folder/folder(description)/file.cap results in folder/folder(description)/file.cap cool!

when I add this to a bash script

#/BIN/BASH

capfiles=($(find <path> -iname *.cap | sed ’s/(/\\(/‘ |sed ’s/)/\\)/‘))

for i in “${capfiles[@]}”;do
     tshark -r $i -T fields -e dns.qry.name |sort u > $i.uniquefqdns2lookup.txt

done

I get

'tshark: The file "folder/folder\(description\)/file.cap" doesn't exist.
'tshark: The file folder/folder\(description\)/file.cap" doesn't exist.
'tshark: The file folder/folder\(description\)/file.cap" doesn't exist. 

I've tried playing with ./ in the patch as an explicit character with no luck. that output looks like:

'tshark: The file "./"folder/folder\(description\)/file.cap" doesn't exist.
'tshark: The file "./folder/folder\(description\)/file.cap" doesn't exist.
'tshark: The file "./folder/folder\(description\)/file.cap" doesn't exist. 

What am I missing? Am i totally off with this?

carter

Posted 2014-12-23T15:10:51.853

Reputation: 25

change #/BIN/BASH to #!/bin/bash. – αғsнιη – 2014-12-23T15:40:01.987

Answers

0

In addition to KasiyA's comment,

  • Make sure your quotes are the right way. In your question, the sed patterns are shown ending with a backquote (`) rather than a forward quote ('). I don't know if that's actually the case in your script.
  • Put the $i in double quotes ("$i") (see this answer).
  • You may not actually need the backslashes, depending on tshark's settings. Using "$i" will preserve the parentheses in your filename. Tshark is probably looking for a file with the literal \ in the name. Try

    capfiles=($(find <path> -iname *.cap )
    

and see what you get.

cxw

Posted 2014-12-23T15:10:51.853

Reputation: 1 389

I had to add another bracket at the end but here is my output (no change)

“tcpdumps/tcpdumpLog(something)/traffic.cap tcpdumps/tcpdumpLog(something)/traffic.cap tcpdumps/tcpdumpLog(something)/traffic.cap tcpdumps/tcpdumpLog(something)/traffic.cap tcpdumps/tcpdumpLog(something)/traffic.cap”

where do the leading and tailing double quotes come from? – carter – 2014-12-23T22:37:17.930

Think I answered my own question – carter – 2014-12-23T22:41:54.853

Think I answered my own question about the double quotes. That had no effect on the original issue. – carter – 2014-12-23T22:47:44.570

@carter so what did the problem turn out to be? Please post and accept your own answer if necessary so the question won't be on the "unanswered" list. Thanks! – cxw – 2014-12-28T10:17:57.623