Author Topic: GREP help...  (Read 392 times)

Jaded

  • The Codfather
  • Formerly known as Jaded
GREP help...
« on: 20 March, 2024, 10:52:46 am »
How can I find (so that I can replace) the first instance of a character in every line of a text file?

I wish to replace the first space with a TAB. The spaces aren't the same number of characters into the lines. There are spaces further in the lines, that I want to keep.

I'm using BBEdit, but getting nowhere, slowly.
It is simpler than it looks.

Re: GREP help...
« Reply #1 on: 20 March, 2024, 10:57:01 am »
You need sed for that
Google is your friend...

Re: GREP help...
« Reply #2 on: 20 March, 2024, 11:05:33 am »
Straight off Google.
sed 's/ /'$'\t''/' filename

https://stackoverflow.com/questions/47010412/replace-first-space-on-each-line-by-a-tab

This works for me rather than \t   Seemingly the syntax for \t as TAB character is not universal (I am using bash on Fedora)
sed 's/ /'$'\tab''/' filename

Jaded

  • The Codfather
  • Formerly known as Jaded
Re: GREP help...
« Reply #3 on: 20 March, 2024, 11:13:36 am »
Well, I had a brainwave and used Excel to import the text file, then converted the first column text using space as the eliminator.

Thanks for your help,

It is simpler than it looks.