1

I have a file.txt such as : that contains:

file1
file2
fil3

and I would like to print :

/beegfs/data/me/these/file1/run_program/file.m8
/beegfs/data/me/these/file2/run_program/file.m8
/beegfs/data/me/these/file3/run_program/file.m8

To do so I used :

sed 's_.*_"/beegfs/data/me/these/&/run_program/file.m8"' file.txt

But it seems that there is something wrong with the _ character ...

chippycentra
  • 879
  • 1
  • 6
  • 15
  • 1
    The command is `s/something/someelse/` - you need trailing closing `_`. Secondly in your command there is a `_` in `run_program` - pick a unique character. – KamilCuk Nov 06 '19 at 13:31
  • But I need the _ in the print – chippycentra Nov 06 '19 at 13:39
  • 2
    Choose a different separator. Ex `~` is free. `s~something~someelse~` – KamilCuk Nov 06 '19 at 13:40
  • see also: https://stackoverflow.com/questions/5864146/use-slashes-in-sed-replace ... also, remove the double quotes if you want expected output as shown in question – Sundeep Nov 06 '19 at 13:41

1 Answers1

2

The following could work:

sed 's~.*~/beegfs/data/me/these/&/run_program/file.m8~' file.txt

Pick s command separator that does not exist in replacement string. I see ~ does not exist, so I used it.

The double quotes " inside single quotes ' are interpreted literally. As you don't want them in the output, remove them.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
KamilCuk
  • 120,984
  • 8
  • 59
  • 111