Sunday, July 10, 2022

[SOLVED] How to copy string before comma in file and paste it later in file after slash

Issue

How can I use sed to copy before comma and paste after slash in a file?

Example:

text1,Information /
text2,Information /
text3,Information /

and I want

text1,Information /text1
text2,Information /text2
text3,Information /text3

Solution

This works with your example:

sed -r 's@(.*),(.*)/@\1,\2/\1@' <file_path>

The idea is that groups (between parentheses) are referenced in the substitution part.



Answered By - WSchmitt
Answer Checked By - Mildred Charles (WPSolving Admin)