Hi there, Unix Gurus
Back in September last year you helped me find a way to
extract the words in brackets in a textfile to a new one.
In that case my textfile was made up of sentences containing an only bracketed word per sentence/line:
1. If the boss's son had been [kidnapped], someone would have asked for money by now.
2. Look, I haven't [committed] a crime, so why can't you let me go?
....
Bur I am trying in vain to do the same but this time on a file full of different texts, not sentences.
...Many astronauts [have] travelled [in] space, but now, ordinary people [are] travelling [in] space too. Dennis Tito [is] over 60 years old, [but] he [hasn't] stopped working yet. In fact, [he] is very active, and [in] 2001, he [did] something amazing. He [became] the world's first [space] tourist. So ... [who] is Dennis Tito? Where [does] he come [from] ? How [did] he become [a] space [tourist] ? Tito [comes] from [the] United States. He was [born] in New York, but [he] has [been] [living] in California [for] many years. He [is] a very rich [and] successful [businessman]...
The following code only extracts the last bracketed word.
sed 's/\(.*\[\).*\(\].*\)/\1\2/g' inputfile > outputfile
As I asked back then, adding the blanked out bracketed words to a new file would be a bonus.
Any help infinitely appreciated.