0

I have a file containing string like: ./intercompany.rb[1:1] | passed | 9 minutes 7 seconds |

I want to remove the string coming after [ character. Output should be ./intercompany.rb

How can we do this in shell script??

Amit
  • 72
  • 2
  • 13

2 Answers2

0
s='./intercompany.rb[1:1] | passed | 9 minutes 7 seconds |'
echo "${s%%[*}"

See http://wiki.bash-hackers.org/syntax/pe and/or BashFAQ #100.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0

With sed:

sed 's/\[.*//' < file
Arndt Jonasson
  • 856
  • 1
  • 6
  • 14