Reputation: 14463
I have never used awk or sed. I am trying to replace
aaa
{
with
aaa
{
bbb
I tried different solutions using sed/awk, but couldn't figure it out.
awk '{gsub("aaa\n{", "aaa\n{\tbbb")}1' file.txt
Could you please help me on how to do it.
Upvotes: 0
Views: 1118
Reputation: 71
awk with getline
awk '/aaa/ {print;getline} /{/ { print ;print "\tbbb";next}1 ' file
Upvotes: 0
Reputation: 58578
This might work for you (GNU sed):
sed '/^aaa$/!b;n;/^{$/a\\tbbb' file
Upvotes: 0
Reputation: 5318
With awk
:
awk '{print} /^aaa$/{i=NR} /^{$/ && NR==i+1 {print "\tbbb"}' File
Output:
aaa
{
bbb
sdjdhsjdhdsd
ds
ddsdsdsd
aaa
{
bbb
Upvotes: 1