Hi.. I'm into a bump after trying to solve this prob.. i've a file with contents like below.
<blankline>
'pgmId' : 'UNIX',
'pgmData' : 'textfile',
'author' : 'admin',
.......
Now i'm trying to insert a new data after pgmId. so the final output will be like:
<blankline>
'pgmId' : 'UNIX',
'moduleId' : 'DEFAULT',
'pgmData' : 'textfile',
'author' : 'admin',
.......
I tried to fix this with a sed command like:
sed "/pgmId/{G;}/" ./tempFile | sed -e "s/^$/\ 'moduleId\' \: \'DEFAULT\'\,/1">>./tempFile1
But this command is replacing all the blank lines with moduleId.
could anyone help me out?
thanks in advance.
Arjun
sed '/pgmId/a\
new_data' filename
In nawk ..
$ echo $newline
'moduleId' : 'DEFAULT',
$
$ nawk -v var="$newline" '/.pgmId/{print $0"\n"var}!/.pgmId/' infile
'pgmId' : 'UNIX',
'moduleId' : 'DEFAULT',
'pgmData' : 'textfile',
'author' : 'admin',
ni2
4
Hi,
A quick search in this forum for "sed insert line after text" led to this sed.. Add new line after finding text
$ echo "'pgmId' : 'UNIX',
'pgmData' : 'textfile',
'author' : 'admin'," | sed "/pgmId/ a\'moduleId':'DEFAULT'"
'pgmId' : 'UNIX',
'moduleId':'DEFAULT'
'pgmData' : 'textfile',
'author' : 'admin',
HTH
Sed variant..
sed 's/pgmId.*$/&\nnew_data/' inputfile
Hi michaelrozar17
Registered User
while using this
sed 's/pgmId.*$/&\nnew_data/' inputfile
i'm getting the following error:
sed: Function /pgmId/ a\'moduleId':'DEFAULT' cannot be parsed.
---------- Post updated at 02:05 PM ---------- Previous update was at 01:46 PM ----------
for all the answers given above, i'm able to add just moduleId default..
I wanted to add the line as
'moduleId' : 'DEFAULT',
the error i'm getting is that the above said line cannot be parsed
Ok..try as
sed "s/pgmId.*$/&\n'moduleId':'DEFAULT',/" inputfile
ya... This is working fyn.. Thanks all