Replace only first instance of a character
Clash Royale CLAN TAG#URR8PPP
for example I have scv file which looks like
a1, b1, c1, d1
a2, b2, c2, d2
a3, b3, c3, d3
What I want to do is to replace the first comma ,
with the semicolon ;
. The position of first comma can be variable (a
in the rows n
and m
can have different lengths). Finally my file shall look like
a1; b1, c1, d1
a2; b2, c2, d2
a3; b3, c3, d3
The other commas have to remain. Can somebody please tell me the most simple solution?
PS my solution doesn't work: sed '/s/,/;/g' file.csv
text-processing sed csv
|
show 3 more comments
for example I have scv file which looks like
a1, b1, c1, d1
a2, b2, c2, d2
a3, b3, c3, d3
What I want to do is to replace the first comma ,
with the semicolon ;
. The position of first comma can be variable (a
in the rows n
and m
can have different lengths). Finally my file shall look like
a1; b1, c1, d1
a2; b2, c2, d2
a3; b3, c3, d3
The other commas have to remain. Can somebody please tell me the most simple solution?
PS my solution doesn't work: sed '/s/,/;/g' file.csv
text-processing sed csv
3
Dosed 's/,/;/' file.csv
satisfy you?
– Costas
Jul 25 '16 at 13:20
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
I have used already the sed command, but just with/g
at the end - >sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.
– Guforu
Jul 25 '16 at 13:30
1
Withg
sed change all commas in line, without it - just first. It cannot be truesed "s/,/;/g"
do work andsed "s/,/;/"
gets error. If you sence with sed trywhile IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37
|
show 3 more comments
for example I have scv file which looks like
a1, b1, c1, d1
a2, b2, c2, d2
a3, b3, c3, d3
What I want to do is to replace the first comma ,
with the semicolon ;
. The position of first comma can be variable (a
in the rows n
and m
can have different lengths). Finally my file shall look like
a1; b1, c1, d1
a2; b2, c2, d2
a3; b3, c3, d3
The other commas have to remain. Can somebody please tell me the most simple solution?
PS my solution doesn't work: sed '/s/,/;/g' file.csv
text-processing sed csv
for example I have scv file which looks like
a1, b1, c1, d1
a2, b2, c2, d2
a3, b3, c3, d3
What I want to do is to replace the first comma ,
with the semicolon ;
. The position of first comma can be variable (a
in the rows n
and m
can have different lengths). Finally my file shall look like
a1; b1, c1, d1
a2; b2, c2, d2
a3; b3, c3, d3
The other commas have to remain. Can somebody please tell me the most simple solution?
PS my solution doesn't work: sed '/s/,/;/g' file.csv
text-processing sed csv
text-processing sed csv
edited Jul 25 '16 at 21:00
Gilles
533k12810721594
533k12810721594
asked Jul 25 '16 at 13:18
GuforuGuforu
203149
203149
3
Dosed 's/,/;/' file.csv
satisfy you?
– Costas
Jul 25 '16 at 13:20
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
I have used already the sed command, but just with/g
at the end - >sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.
– Guforu
Jul 25 '16 at 13:30
1
Withg
sed change all commas in line, without it - just first. It cannot be truesed "s/,/;/g"
do work andsed "s/,/;/"
gets error. If you sence with sed trywhile IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37
|
show 3 more comments
3
Dosed 's/,/;/' file.csv
satisfy you?
– Costas
Jul 25 '16 at 13:20
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
I have used already the sed command, but just with/g
at the end - >sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.
– Guforu
Jul 25 '16 at 13:30
1
Withg
sed change all commas in line, without it - just first. It cannot be truesed "s/,/;/g"
do work andsed "s/,/;/"
gets error. If you sence with sed trywhile IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37
3
3
Do
sed 's/,/;/' file.csv
satisfy you?– Costas
Jul 25 '16 at 13:20
Do
sed 's/,/;/' file.csv
satisfy you?– Costas
Jul 25 '16 at 13:20
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
I have used already the sed command, but just with
/g
at the end - > sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.– Guforu
Jul 25 '16 at 13:30
I have used already the sed command, but just with
/g
at the end - > sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.– Guforu
Jul 25 '16 at 13:30
1
1
With
g
sed change all commas in line, without it - just first. It cannot be true sed "s/,/;/g"
do work and sed "s/,/;/"
gets error. If you sence with sed try while IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37
With
g
sed change all commas in line, without it - just first. It cannot be true sed "s/,/;/g"
do work and sed "s/,/;/"
gets error. If you sence with sed try while IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37
|
show 3 more comments
2 Answers
2
active
oldest
votes
Pure bash solution
while IFS=, read -r a b ; do echo "$a;$b" ; done <file.csv
Or just for fun
paste -d; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)
1
Try the first one on an input like1,2,
or1,2
or1
. See also Why is using a shell loop to process text considered bad practice?
– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses1,2
, but not the1,2,
or1
cases though. Note that,
is not special, you don't need to quote it.
– Stéphane Chazelas
Jul 25 '16 at 15:47
add a comment |
The g
in:
sed 's/,/;/g'
is for globally, that is to substitute all occurrences of ,
with ;
.
If you want to do only one substitution per line, take off the g
:
sed 's/,/;/'
And for completeness:
You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence:
sed 's/,/;/2'
With GNU sed
, you can also substitute all occurrences starting from the second one (in effect, all but the first one) with:
sed 's/,/;/2g'
To perform two substitutions, in this case:
sed 's/,/;/;s/,/;/'
Where it gets more complicated is when the pattern can match the substitution (or parts of it), for instance when substituting ,
with <,>
. sed
has no built-in mechanism to address that. You may want to use perl
instead in that case:
perl -pe '$i = 0; s/,/$i++ < 2 ? "<,>" : $&/ge'
perl -pe
is perl
's sed
mode (note that the regex syntax is different). With the e
flag of the s///
operator, the replacement is considered as code. There, we replace ,
with <,>
only when our incremented counter is < 2. Otherwise, we replace the ,
with itself ($&
actually referring to the matched string like &
in sed
's s
command).
You can generalise that for a range or set of substitutions. Like for 3rd to 5th and 7th to 9th:
perl -pe '$i = 0; s/,/$i++;
$i >=3 && $i <= 5 || $i >= 7 && $i <= 9 ? "<,>" : $&/ge'
To replace only the first occurrence in the whole input (as opposed to in each line):
sed -e 's/,/;/;t done' -e b -e :done -e 'n;b done'
That is, upon the first successful substitution, go into a loop that just prints the rest of the input.
With GNU sed
, you can use the pseudo address 0:
sed '0,/,/s//;/'
Note
I suppose it's a typo, but the
sed '/s/,/;/g'
command you wrote in your question is something completely different.
That's doing:
sed '/start/,/end/g'
where start
is s
and end
is ;
. That is, applying the g
command (replace the pattern space with the content of the hold space (empty here as you never hold anything)) for sections of the file in between one that contains s
and the next one that contains ;
.
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f298139%2freplace-only-first-instance-of-a-character%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Pure bash solution
while IFS=, read -r a b ; do echo "$a;$b" ; done <file.csv
Or just for fun
paste -d; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)
1
Try the first one on an input like1,2,
or1,2
or1
. See also Why is using a shell loop to process text considered bad practice?
– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses1,2
, but not the1,2,
or1
cases though. Note that,
is not special, you don't need to quote it.
– Stéphane Chazelas
Jul 25 '16 at 15:47
add a comment |
Pure bash solution
while IFS=, read -r a b ; do echo "$a;$b" ; done <file.csv
Or just for fun
paste -d; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)
1
Try the first one on an input like1,2,
or1,2
or1
. See also Why is using a shell loop to process text considered bad practice?
– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses1,2
, but not the1,2,
or1
cases though. Note that,
is not special, you don't need to quote it.
– Stéphane Chazelas
Jul 25 '16 at 15:47
add a comment |
Pure bash solution
while IFS=, read -r a b ; do echo "$a;$b" ; done <file.csv
Or just for fun
paste -d; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)
Pure bash solution
while IFS=, read -r a b ; do echo "$a;$b" ; done <file.csv
Or just for fun
paste -d; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)
edited Jul 25 '16 at 15:28
answered Jul 25 '16 at 14:02
CostasCostas
12.6k1129
12.6k1129
1
Try the first one on an input like1,2,
or1,2
or1
. See also Why is using a shell loop to process text considered bad practice?
– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses1,2
, but not the1,2,
or1
cases though. Note that,
is not special, you don't need to quote it.
– Stéphane Chazelas
Jul 25 '16 at 15:47
add a comment |
1
Try the first one on an input like1,2,
or1,2
or1
. See also Why is using a shell loop to process text considered bad practice?
– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses1,2
, but not the1,2,
or1
cases though. Note that,
is not special, you don't need to quote it.
– Stéphane Chazelas
Jul 25 '16 at 15:47
1
1
Try the first one on an input like
1,2,
or 1,2
or 1
. See also Why is using a shell loop to process text considered bad practice?– Stéphane Chazelas
Jul 25 '16 at 14:36
Try the first one on an input like
1,2,
or 1,2
or 1
. See also Why is using a shell loop to process text considered bad practice?– Stéphane Chazelas
Jul 25 '16 at 14:36
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
@StéphaneChazelas Thank you for comment, I have -r option added.
– Costas
Jul 25 '16 at 15:33
good. That addresses
1,2
, but not the 1,2,
or 1
cases though. Note that ,
is not special, you don't need to quote it.– Stéphane Chazelas
Jul 25 '16 at 15:47
good. That addresses
1,2
, but not the 1,2,
or 1
cases though. Note that ,
is not special, you don't need to quote it.– Stéphane Chazelas
Jul 25 '16 at 15:47
add a comment |
The g
in:
sed 's/,/;/g'
is for globally, that is to substitute all occurrences of ,
with ;
.
If you want to do only one substitution per line, take off the g
:
sed 's/,/;/'
And for completeness:
You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence:
sed 's/,/;/2'
With GNU sed
, you can also substitute all occurrences starting from the second one (in effect, all but the first one) with:
sed 's/,/;/2g'
To perform two substitutions, in this case:
sed 's/,/;/;s/,/;/'
Where it gets more complicated is when the pattern can match the substitution (or parts of it), for instance when substituting ,
with <,>
. sed
has no built-in mechanism to address that. You may want to use perl
instead in that case:
perl -pe '$i = 0; s/,/$i++ < 2 ? "<,>" : $&/ge'
perl -pe
is perl
's sed
mode (note that the regex syntax is different). With the e
flag of the s///
operator, the replacement is considered as code. There, we replace ,
with <,>
only when our incremented counter is < 2. Otherwise, we replace the ,
with itself ($&
actually referring to the matched string like &
in sed
's s
command).
You can generalise that for a range or set of substitutions. Like for 3rd to 5th and 7th to 9th:
perl -pe '$i = 0; s/,/$i++;
$i >=3 && $i <= 5 || $i >= 7 && $i <= 9 ? "<,>" : $&/ge'
To replace only the first occurrence in the whole input (as opposed to in each line):
sed -e 's/,/;/;t done' -e b -e :done -e 'n;b done'
That is, upon the first successful substitution, go into a loop that just prints the rest of the input.
With GNU sed
, you can use the pseudo address 0:
sed '0,/,/s//;/'
Note
I suppose it's a typo, but the
sed '/s/,/;/g'
command you wrote in your question is something completely different.
That's doing:
sed '/start/,/end/g'
where start
is s
and end
is ;
. That is, applying the g
command (replace the pattern space with the content of the hold space (empty here as you never hold anything)) for sections of the file in between one that contains s
and the next one that contains ;
.
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
add a comment |
The g
in:
sed 's/,/;/g'
is for globally, that is to substitute all occurrences of ,
with ;
.
If you want to do only one substitution per line, take off the g
:
sed 's/,/;/'
And for completeness:
You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence:
sed 's/,/;/2'
With GNU sed
, you can also substitute all occurrences starting from the second one (in effect, all but the first one) with:
sed 's/,/;/2g'
To perform two substitutions, in this case:
sed 's/,/;/;s/,/;/'
Where it gets more complicated is when the pattern can match the substitution (or parts of it), for instance when substituting ,
with <,>
. sed
has no built-in mechanism to address that. You may want to use perl
instead in that case:
perl -pe '$i = 0; s/,/$i++ < 2 ? "<,>" : $&/ge'
perl -pe
is perl
's sed
mode (note that the regex syntax is different). With the e
flag of the s///
operator, the replacement is considered as code. There, we replace ,
with <,>
only when our incremented counter is < 2. Otherwise, we replace the ,
with itself ($&
actually referring to the matched string like &
in sed
's s
command).
You can generalise that for a range or set of substitutions. Like for 3rd to 5th and 7th to 9th:
perl -pe '$i = 0; s/,/$i++;
$i >=3 && $i <= 5 || $i >= 7 && $i <= 9 ? "<,>" : $&/ge'
To replace only the first occurrence in the whole input (as opposed to in each line):
sed -e 's/,/;/;t done' -e b -e :done -e 'n;b done'
That is, upon the first successful substitution, go into a loop that just prints the rest of the input.
With GNU sed
, you can use the pseudo address 0:
sed '0,/,/s//;/'
Note
I suppose it's a typo, but the
sed '/s/,/;/g'
command you wrote in your question is something completely different.
That's doing:
sed '/start/,/end/g'
where start
is s
and end
is ;
. That is, applying the g
command (replace the pattern space with the content of the hold space (empty here as you never hold anything)) for sections of the file in between one that contains s
and the next one that contains ;
.
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
add a comment |
The g
in:
sed 's/,/;/g'
is for globally, that is to substitute all occurrences of ,
with ;
.
If you want to do only one substitution per line, take off the g
:
sed 's/,/;/'
And for completeness:
You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence:
sed 's/,/;/2'
With GNU sed
, you can also substitute all occurrences starting from the second one (in effect, all but the first one) with:
sed 's/,/;/2g'
To perform two substitutions, in this case:
sed 's/,/;/;s/,/;/'
Where it gets more complicated is when the pattern can match the substitution (or parts of it), for instance when substituting ,
with <,>
. sed
has no built-in mechanism to address that. You may want to use perl
instead in that case:
perl -pe '$i = 0; s/,/$i++ < 2 ? "<,>" : $&/ge'
perl -pe
is perl
's sed
mode (note that the regex syntax is different). With the e
flag of the s///
operator, the replacement is considered as code. There, we replace ,
with <,>
only when our incremented counter is < 2. Otherwise, we replace the ,
with itself ($&
actually referring to the matched string like &
in sed
's s
command).
You can generalise that for a range or set of substitutions. Like for 3rd to 5th and 7th to 9th:
perl -pe '$i = 0; s/,/$i++;
$i >=3 && $i <= 5 || $i >= 7 && $i <= 9 ? "<,>" : $&/ge'
To replace only the first occurrence in the whole input (as opposed to in each line):
sed -e 's/,/;/;t done' -e b -e :done -e 'n;b done'
That is, upon the first successful substitution, go into a loop that just prints the rest of the input.
With GNU sed
, you can use the pseudo address 0:
sed '0,/,/s//;/'
Note
I suppose it's a typo, but the
sed '/s/,/;/g'
command you wrote in your question is something completely different.
That's doing:
sed '/start/,/end/g'
where start
is s
and end
is ;
. That is, applying the g
command (replace the pattern space with the content of the hold space (empty here as you never hold anything)) for sections of the file in between one that contains s
and the next one that contains ;
.
The g
in:
sed 's/,/;/g'
is for globally, that is to substitute all occurrences of ,
with ;
.
If you want to do only one substitution per line, take off the g
:
sed 's/,/;/'
And for completeness:
You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence:
sed 's/,/;/2'
With GNU sed
, you can also substitute all occurrences starting from the second one (in effect, all but the first one) with:
sed 's/,/;/2g'
To perform two substitutions, in this case:
sed 's/,/;/;s/,/;/'
Where it gets more complicated is when the pattern can match the substitution (or parts of it), for instance when substituting ,
with <,>
. sed
has no built-in mechanism to address that. You may want to use perl
instead in that case:
perl -pe '$i = 0; s/,/$i++ < 2 ? "<,>" : $&/ge'
perl -pe
is perl
's sed
mode (note that the regex syntax is different). With the e
flag of the s///
operator, the replacement is considered as code. There, we replace ,
with <,>
only when our incremented counter is < 2. Otherwise, we replace the ,
with itself ($&
actually referring to the matched string like &
in sed
's s
command).
You can generalise that for a range or set of substitutions. Like for 3rd to 5th and 7th to 9th:
perl -pe '$i = 0; s/,/$i++;
$i >=3 && $i <= 5 || $i >= 7 && $i <= 9 ? "<,>" : $&/ge'
To replace only the first occurrence in the whole input (as opposed to in each line):
sed -e 's/,/;/;t done' -e b -e :done -e 'n;b done'
That is, upon the first successful substitution, go into a loop that just prints the rest of the input.
With GNU sed
, you can use the pseudo address 0:
sed '0,/,/s//;/'
Note
I suppose it's a typo, but the
sed '/s/,/;/g'
command you wrote in your question is something completely different.
That's doing:
sed '/start/,/end/g'
where start
is s
and end
is ;
. That is, applying the g
command (replace the pattern space with the content of the hold space (empty here as you never hold anything)) for sections of the file in between one that contains s
and the next one that contains ;
.
edited Jan 10 at 12:26
answered Jul 25 '16 at 13:38
Stéphane ChazelasStéphane Chazelas
302k56568920
302k56568920
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
add a comment |
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
Note that to only replace 1st occurence in a file (not in a line) you need to do something else. See: linuxconfig.org/…
– Nux
Jan 10 at 12:15
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
@Nux. Thanks, I've added a section about that.
– Stéphane Chazelas
Jan 10 at 14:18
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f298139%2freplace-only-first-instance-of-a-character%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Do
sed 's/,/;/' file.csv
satisfy you?– Costas
Jul 25 '16 at 13:20
no, I have got next error message: sed: -e expression #1, char 7: missing command
– Guforu
Jul 25 '16 at 13:25
Do you miss quotes?
– Costas
Jul 25 '16 at 13:27
I have used already the sed command, but just with
/g
at the end - >sed /s/,/;/g
. Your code produces by me an error message. Anyway, I'm not sure this code will change all the commas. I need to change only the firs one.– Guforu
Jul 25 '16 at 13:30
1
With
g
sed change all commas in line, without it - just first. It cannot be truesed "s/,/;/g"
do work andsed "s/,/;/"
gets error. If you sence with sed trywhile IFS=, read a b ; do echo "$a;$b" ; done <file.csv
– Costas
Jul 25 '16 at 13:37