0

In a simple case, let say we have some standard error:

$ ls /fake/file
ls: /fake/file: No such file or directory

QUESTION: Is it possible to parse out "/fake/file" from the standard error without having to write it out to a file first? For example:

$ ls /fake/file 2> tmp.file; sed 's/.* \(.*\):.*/\1/' tmp.file
/fake/file
csiu
  • 3,159
  • 2
  • 24
  • 26

2 Answers2

1

Something like this?

ls /fake/file 2>&1 | awk -F: '{print $2}'
ahamed101
  • 110
  • 2
  • 9
  • The parsing is not exactly correct, but this: `ls /fake/file 2>&1` is what I was looking for. Thanks! – csiu Jan 15 '14 at 02:00
0

either way should fetch you the filename

ls /fake/file 2>&1 | awk -F: '{print $2}' | awk '{print $3}'

or

ls /fake/file 2>&1 | awk '{print $4}' | awk -F: '{print $1}'

or

ls /fake/file 2>&1 | sed 's/.* \(.*\):.*/\1/'