How to use sed to insert character in the beginning of file path?

I need to manipulate one Database file on Solaris 11 in which contains more than 5000 lines of data file path like this:

 '/data1/oradata/DBNAME/system01.dbf',
  '/data7/oradata/DBNAME/undotbs1_01.dbf',
  '/data1/oradata/DBNAME/sysaux01.dbf',
  '/data28/oradata/DBNAME/userdata01.dbf',
  '/data28/oradata/DBNAME/user_data01.dbf',
  '/data128/oradata/DBNAME/undotbs1_02.dbf',
................................................
  '/datadw29/oradata/DBNAME/corp/comm_sd37.dbf',
  '/datadw28/oradata/DBNAME/corp/comm_sd38.dbf',
.................................................................................................
  '/dataidxdw42/oradata/DBNAME/ods/ODS_DATA_IDX_07.dbf',
  '/dataidxdw42/oradata/DBNAME/ods/ODS_DATA_IDX_08.dbf'

,

In these path lines, the first part of path name contains number '/data28/ and three path group with different first part of name. I need to insert one path name: "bck1" in the beginning of each path name. After manipulation, the path name in the file should be like this:

 '/bck1/data1/oradata/DBNAME/system01.dbf',
  '/bck1/data7/oradata/DBNAME/undotbs1_01.dbf',
  '/bck1/data1/oradata/DBNAME/sysaux01.dbf',
  '/bck1/data28/oradata/DBNAME/userdata01.dbf',
  '/bck1/data28/oradata/DBNAME/user_data01.dbf',
  '/bck1/data128/oradata/DBNAME/undotbs1_02.dbf',
................................................
  '/bck1/datadw29/oradata/DBNAME/corp/comm_sd37.dbf',
  '/bck1/datadw28/oradata/DBNAME/corp/comm_sd38.dbf',
.................................................................................................
  '/bck1/dataidxdw42/oradata/DBNAME/ods/ODS_DATA_IDX_07.dbf',
  '/bck1/dataidxdw42/oradata/DBNAME/ods/ODS_DATA_IDX_08.dbf'

I tried to use "v" i editor and "sed" to insert first part of path name. it can work on some lines and could not globally make change. I want to learn how to use "sed" to globally update the file path and deal with different number in path name and with different path name. Please help to provide your advice and command here. I will test and come back to report progress. Thanks for your time and help.

How far would

sed 's#/#/bck1/#' file

get you?

1 Like

RudiC:

I have tested. It works. your code can deal with all situation and insert new path text in the beginning of the all path. Thanks a lot. If you can give some explanation about "sed" options such as 's#/#/text/#' , that will help more. I searched on line and could not get more information about these expression. Of course, I will do more search and learning for "sed".

man sed and info sed are profound sources of information. info sed :

RudiC:

Thanks for explanation. I still do not understand. man sed , only tell us 's/REGEXP/REPLACEMENT/FLAGS'. . In your command, 's#/#/text/#' , text is REPLACEMENT. So 1st #, 2nd # and 3rd # stand for what? Wildcard for path name? Are they extended expressio or something else? I checked online and other books. I could not find answer. Can you please explain your command in details? Sorry for this. I want to really know the programming logic of your command.
Thanks in advance for your help.

Did you read and understand my quote from info sed ?

So my command reads

s#pattern#replacement#

as the / is part of both pattern and replacement. The delimiter or separator is # , the pattern is / , and the replacement is /bck1/ .

RudiC:

Thanks a lot. Here # is delimiter. I thought the # is some extended expression and tried to find more information without success. Now, I learned from you. I will keep this explanation for the future usage. Thanks again.

Moderator comments were removed during original forum migration.