-1

I would like to know if you have a file name > abc (1).bin or > abc (1).txt files, how do you read them. The files are with the space and bracket before the .bin or .txt extension.

To read the .bin file I have a tool, I can read it easily if I remove the "space and (1)" from the filename. But when I have this space and bracket (1).bin name, I can not read it.

When I cat a .txt file, it works.. but it doesn't work with the .bin file. Below are the requested tests:

$ cat full_logs-10.2.0.103-2018.02.07\ \(1\).txt 
hello,
this is a test.

--------xxxxxxx------xxxxxxx------------xxxxxxx--------

$ LogAnalyzeRebirth -p -x ./ full_logs-2018.02.07\ \(1\).bin 
usage: LogAnalyzeRebirth [-h] [-A] [-B] [-C] [-D] [-E] [-F]
                         [-G GRAPH [GRAPH ...]] [-H] [-I [HISTOGRAM]] [-L]
                         [-M] [-N] [-P [PDF]] [-R] [-S] [-T] [-U] [-V] [-b]
                         [-c] [-e] [--moo] [-f] [-g] [-i] [-k] [-l] [-m] [-n]
                         [-o] [-p PATH] [-q] [-r] [-s] [-t] [-v] [-x EXTRACT]
                         [-z]
LogAnalyzeRebirth: error: argument -p/--path: expected 1 argument(s)

--------xxxxxxx------xxxxxxx------------xxxxxxx--------

$ LogAnalyzeRebirth.py -p ./ -x "full_logs-10.2.0.103-2018.02.07 (1).bin" 

(\ /)                      (\ /)
( . .)      LogAnalyzeRebirth     (. . )
c(")(")                  (")(")o

sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
Extract failed.
LogAnalyzeRebirth can't find full_logs-10.2.0.103-2018.02.07 (1).bin
No such file or directory : ./full_logs-10.2.0.103-2018.02.07 (1)/dmesg

---   Firmware_version   ---

No such file or directory : ./full_logs-10.2.0.103-2018.02.07 (1)/version.txt

--------xxxxxxx------xxxxxxx------------xxxxxxx--------
David Foerster
  • 36,264
  • 56
  • 94
  • 147
Imrank
  • 51
  • 1
    If you are reading in a shell, put the filename between quotes i.e. cat "> abc (1).bin". – muclux Feb 08 '18 at 07:56
  • cat was only an example. Whatever you want to do with your .bin file, put the file name between quotes and the characters used in the name won't matter. – muclux Feb 08 '18 at 08:01
  • I have edited the question with my explanation. and when I did that "cat "> abc (1).bin" it didn't work. Loganalyzer says: command not found. – Imrank Feb 08 '18 at 08:02
  • Your command error says the path should come after -p. You put -p -x ./.... – muru Feb 08 '18 at 08:03
  • Your command would be LogAnalyzeRebirth -x -p ./" full_logs-2018.02.07 (1).bin" (if there really is a space at the beginning of the file name - if not, omit the space between " and 'f'.) Possibly after -x you have to insert a value for EXTRACT - see the syntax of your command. – muclux Feb 08 '18 at 08:04
  • Yes, my command is the same.. there is no space in the beginning of the filename however the space is at the end. And when I put the filename in " " it runs the command but with errors like it can not find the directories, I am editing the main post just to show you the output. – Imrank Feb 08 '18 at 08:10
  • and the only magic is, when I go and edit the name of the file manually like removing 'space (1)" from the GUI it works well, and no issues. But I do not want to go and edit filename manually and would like to achieve it from the CLI. – Imrank Feb 08 '18 at 08:14
  • 2
    It looks like the script you are using passes the file name on to another script or program and there the quotes are missing (as they already have been stripped by the shell). So you would have to edit your script to put quotes around the filename, too. – muclux Feb 08 '18 at 08:20
  • you are right, its using a combination of scripts.. and so far I just know the solution to renaming the file with "mv" to any other name.. and extract it. – Imrank Feb 08 '18 at 08:57
  • well, its not a duplicate post i think. But if you say I shall delete the post. – Imrank Feb 08 '18 at 08:58
  • @Imrank: Please leave it! There's an election to reopen the question (because it's not a duplicate of the other any longer) and then muclux (or anybody else) can post a proper answer. – David Foerster Feb 08 '18 at 11:58
  • 1
    If you can't modify the script itself, one thing you can try is do extra quoting for it: LogAnalyzeRebirth.py -p ./ -x "$(printf %q "full_logs-10.2.0.103-2018.02.07 (1).bin")", but that won't help if the scripts that this script calls are also broken. – muru Feb 08 '18 at 12:31
  • I would rather propose a wrapping script for LogAnalyzeRebirth.py, which would copy the data file to some reasonable name, call LogAnalyzeRebirth.py for the copy and then delete the copy. So there would be no problems with multiple further calls. – muclux Feb 08 '18 at 13:17
  • heyy, finally.. this below worked for me: /* If you can't modify the script itself, one thing you can try is do extra quoting for it: LogAnalyzeRebirth.py -p ./ -x "$(printf %q "full_logs-10.2.0.103-2018.02.07 (1).bin")", but that won't help if the scripts that this script calls are also broken. /* it doesn't show the preview but least it extracted the bin folder well. – Imrank Feb 11 '18 at 07:57

1 Answers1

0

The discussion in the comments showed that the weird filename has to be passed to a script or program which itself is calling other scripts or programs with the filename as a parameter. Therefore enclosing the filename in quotes is not sufficient as the shell removes these quotes and the next call transmits the filename without quotes, making it unusable.

So my idea is to use a wrapper script doLogAnalyze for LogAnalyzeRebirth.py, like this:

#!/bin/bash
tmpfile=$(mktemp /tmp/LogAnalyzeRebirth.XXXXXX) # create temporary file
cp "$1" "$tmpfile"                              # copy to temporay file
LogAnalyzeRebirth.py -p ./ -x "$tmpfile"        # analyze copy
rm "$tmpfile"                                   # delete copy

Calling ./doLogAnalyze "full_logs-10.2.0.103-2018.02.07 (1).bin" should do the job, regardless of how many other programs are used within the main program. No change is made to the original files, as was the wish of the OP.

muclux
  • 5,154
  • hello, this wrapping script didn't work for me and resulted the same as earlier that, it doesn't extract the bin file even using this script. But as said above in the comment,: LogAnalyzeRebirth.py -p ./ -x "$(printf %q "full_logs-10.2.0.103-2018.02.07 (1).bin")" worked for me. Thank you very much, all you guys rock! – Imrank Feb 11 '18 at 08:02