From: The Magnet on
I have data in a file that I need to do a global replace on. Each
line starts like this: 1, 2,

Basically a number then a comma then a space then a number then a
comma then a space.

I need to do a global replace throughout the file so it looks like
this:

1||||2|||| (So number then 4 pipes then number then 4 pipes).

I'm playing with SED but cannot get the regular expression. Any help
please?
From: pk on
On Fri, 6 Aug 2010 14:10:05 -0700 (PDT)
The Magnet <art(a)unsu.com> wrote:

> I have data in a file that I need to do a global replace on. Each
> line starts like this: 1, 2,
>
> Basically a number then a comma then a space then a number then a
> comma then a space.
>
> I need to do a global replace throughout the file so it looks like
> this:
>
> 1||||2|||| (So number then 4 pipes then number then 4 pipes).
>
> I'm playing with SED but cannot get the regular expression. Any help
> please?

sed 's/^\([0-9]\{1,\}\), \([0-9]\{1,\}\)/\1||||\2||||/' file
From: John W. Krahn on
The Magnet wrote:
> I have data in a file that I need to do a global replace on. Each
> line starts like this: 1, 2,
>
> Basically a number then a comma then a space then a number then a
> comma then a space.
>
> I need to do a global replace throughout the file so it looks like
> this:
>
> 1||||2|||| (So number then 4 pipes then number then 4 pipes).
>
> I'm playing with SED but cannot get the regular expression. Any help
> please?

perl -pe's/^(\d+), (\d+), /$1||||$2||||/' yourfile


John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
From: Mart Frauenlob on
On 06.08.2010 23:10, The Magnet wrote:
> I have data in a file that I need to do a global replace on. Each
> line starts like this: 1, 2,
>
> Basically a number then a comma then a space then a number then a
> comma then a space.
>
> I need to do a global replace throughout the file so it looks like
> this:
>
> 1||||2|||| (So number then 4 pipes then number then 4 pipes).
>
> I'm playing with SED but cannot get the regular expression. Any help
> please?

one shell only version:

eris:/tmp# cat tst
1, 2, foo bar
2, 3, bar foo
eris:/tmp# sh -c 'while read first second rest; do printf
"%s||||%s||||%s\n" "${first%%,}" "${second%,}" "$rest"; done <tst'
1||||2||||foo bar
2||||3||||bar foo


From: Mart Frauenlob on
On 07.08.2010 09:12, Mart Frauenlob wrote:
> On 06.08.2010 23:10, The Magnet wrote:
>> I have data in a file that I need to do a global replace on. Each
>> line starts like this: 1, 2,
>>
>> Basically a number then a comma then a space then a number then a
>> comma then a space.
>>
>> I need to do a global replace throughout the file so it looks like
>> this:
>>
>> 1||||2|||| (So number then 4 pipes then number then 4 pipes).
>>
>> I'm playing with SED but cannot get the regular expression. Any help
>> please?
>
> one shell only version:
>
> eris:/tmp# cat tst
> 1, 2, foo bar
> 2, 3, bar foo
> eris:/tmp# sh -c 'while read first second rest; do printf
> "%s||||%s||||%s\n" "${first%%,}" "${second%,}" "$rest"; done <tst'
> 1||||2||||foo bar
> 2||||3||||bar foo
>
>

"${first%%,}" should be: "${first%,}"
 |  Next  |  Last
Pages: 1 2
Prev: bash 4.1 interix
Next: Thinking about a new shell