admin管理员组文章数量:1123502
I am trying to add ,"
after every first number of every line
input.txt
1 In the beginning, God created the heavens and the earth.
2 The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.
3 And God said, “Let there be light,” and there was light.
4 And God saw that the light was good. And God separated the light from the darkness.
5 God called the light Day, and the darkness he called Night. And there was evening and there was morning, the first day.
6 And God said, “Let there be an expanse in the midst of the waters, and let it separate the waters from the waters.”
7 And God made the expanse and separated the waters that were under the expanse from the waters that were above the expanse. And it was so.
8 And God called the expanse Heaven. And there was evening and there was morning, the second day.
9 And God said, “Let the waters under the heavens be gathered together into one place, and let the dry land appear.” And it was so.
10 God called the dry land Earth, and the waters that were gathered together he called Seas. And God saw that it was good.
Output I want to generate is shown below
1,"In the beginning, God created the heavens and the earth.
2,"The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.
3,"And God said, “Let there be light,” and there was light.
4,"And God saw that the light was good. And God separated the light from the darkness.
5,"God called the light Day, and the darkness he called Night. And there was evening and there was morning, the first day.
6,"And God said, “Let there be an expanse in the midst of the waters, and let it separate the waters from the waters.”
7,"And God made the expanse and separated the waters that were under the expanse from the waters that were above the expanse. And it was so.
8,"And God called the expanse Heaven. And there was evening and there was morning, the second day.
9,"And God said, “Let the waters under the heavens be gathered together into one place, and let the dry land appear.” And it was so.
10,"God called the dry land Earth, and the waters that were gathered together he called Seas. And God saw that it was good.
Below is my MWE
#!/bin/bash
cat input.txt|sed 's/ /,"/'
I am trying to add ,"
after every first number of every line
input.txt
1 In the beginning, God created the heavens and the earth.
2 The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.
3 And God said, “Let there be light,” and there was light.
4 And God saw that the light was good. And God separated the light from the darkness.
5 God called the light Day, and the darkness he called Night. And there was evening and there was morning, the first day.
6 And God said, “Let there be an expanse in the midst of the waters, and let it separate the waters from the waters.”
7 And God made the expanse and separated the waters that were under the expanse from the waters that were above the expanse. And it was so.
8 And God called the expanse Heaven. And there was evening and there was morning, the second day.
9 And God said, “Let the waters under the heavens be gathered together into one place, and let the dry land appear.” And it was so.
10 God called the dry land Earth, and the waters that were gathered together he called Seas. And God saw that it was good.
Output I want to generate is shown below
1,"In the beginning, God created the heavens and the earth.
2,"The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.
3,"And God said, “Let there be light,” and there was light.
4,"And God saw that the light was good. And God separated the light from the darkness.
5,"God called the light Day, and the darkness he called Night. And there was evening and there was morning, the first day.
6,"And God said, “Let there be an expanse in the midst of the waters, and let it separate the waters from the waters.”
7,"And God made the expanse and separated the waters that were under the expanse from the waters that were above the expanse. And it was so.
8,"And God called the expanse Heaven. And there was evening and there was morning, the second day.
9,"And God said, “Let the waters under the heavens be gathered together into one place, and let the dry land appear.” And it was so.
10,"God called the dry land Earth, and the waters that were gathered together he called Seas. And God saw that it was good.
Below is my MWE
#!/bin/bash
cat input.txt|sed 's/ /,"/'
Share
Improve this question
asked 17 hours ago
Biki TeronBiki Teron
2382 gold badges4 silver badges13 bronze badges
2
|
1 Answer
Reset to default 2What I would do:
sed -E 's/^[0-9]+/&,"/' file
The regular expression matches as follows:
Node | Explanation |
---|---|
^ |
the beginning of the string anchor |
[0-9]+ |
any character of: '0' to '9' (1 or more times (matching the most amount possible)) |
In the remplacement part, &
is what matched in the left part
本文标签: shellHow add character after every first number in every line using sedStack Overflow
版权声明:本文标题:shell - How add character after every first number in every line using sed? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736572266a1944787.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
nl
and notsed
. But what your specification is unclear, saying the first number in a line. What is the desired output for a line containingbla bla bla 4711 foo bar baz
? – user1934428 Commented 15 hours ago