1

I've been trying to filter a text file, but have not been able to do so.. I've just realized the reason why I am not able to filter it is because what I thought was listed as

Word '\t' phoneme
Word '\t' phoneme
Word '\t' phoneme
Word '\t' phoneme

is not always tab separated. Some of the entries are separated by two space, and others are separated by tab.

Is it possible to change all the spaces between word and phonemes to tab?

<oov> <oov>
A  AH0
A  EY1
A''S    EY1 Z
A'BODY  EY1 B AA2 D IY0
A'COURT EY1 K AO2 R T
A'D EY1 D
A'GHA   EY1 G AH0
A'GOIN  EY1 G OY1 N
A'LL    EY1 L
A'M EY1 M
A'MIGHTY    EY1 M AY1 T IY0
A'MIGHTY'S  EY1 M AY1 T IY0 Z
A'MOST  EY1 M OW2 S T
A'N'T   EY1 AH0 N T
A'PENNY EY1 P EH2 N IY0
A'READY EY1 R IY1 D IY0
A'RIGHT EY1 R AY2 T
A'RONY  EY1 R OW1 N IY0
A'S  EY1 Z
A'TER   EY1 T ER0
A'TERNOON   EY1 T ER0 N UW1 N
  • 1
    Do you want to replace all contiguous sequences of whitespace by single tabs - or just the first such sequence on each line? – steeldriver Apr 19 '17 at 13:16
  • I just want to replace all spaces that are between word and the set of phonemes. – Bob Burt Apr 19 '17 at 13:36
  • And which ones are those? The first space on every line? – terdon Apr 19 '17 at 14:14
  • yes.. that would be it. But it is two spaces.. – Bob Burt Apr 19 '17 at 14:21
3

Assuming you want to replace the first sequence of whitespace on a line with a single tab, this would work with GNU sed:

$ sed -Ee 's/[ \t]+/\t/' lexicon
<oov>   <oov>
A       AH0
A       EY1
A''S    EY1 Z
A'BODY  EY1 B AA2 D IY0
...

Add a g after the final slash to change all whitespace runs to single tabs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.