Sample Header Ad - 728x90

Double backslash disappears when printed in a loop

0 votes
1 answer
51 views
I have a script that joins together various lists of data fields which then needs to have a few more columns added. The file generated looks like this: $ cat compiled.csv "name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\\network_user1"], "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "name":"Network Rule 2", "description":"Network Rule 2", "from":["internal"], "source":["any"], "user":["domain\\network_user2"], "to":["external"], "destination":["host.example.com","10.2.1.1"], "port":["23","25"], "name":"Network Rule 3", "description":"Network Rule 3", "from":["internal"], "source":["any"], "user":["domain\\network_user3"], "to":["external"], "destination":["host.example.com","10.3.4.1"], "port":["80","143"], I'm trying to append a few more fields (all the same) to the list; these fields would be something like... "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes" The final output should look like this: "name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], "user":["domain\\network_user1"], "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes" "name":"Network Rule 2", "description":"Network Rule 2", "from":["internal"], "source":["any"], "user":["domain\\network_user2"], "to":["external"], "destination":["host.example.com","10.2.1.1"], "port":["23","25"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes" "name":"Network Rule 3", "description":"Network Rule 3", "from":["internal"], "source":["any"], "user":["domain\\network_user3"], "to":["external"], "destination":["host.example.com","10.3.4.1"], "port":["80","143"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes" When I try to append the fields in a loop, my double backslash disappears both when running the following command in a script and directly in the shell. while read LINE; do echo $LINE \"access\":\"allow\", \"time\":\"00:00:00-23:59:59\", \"notify\":\"yes\" done completed_list.csv Instead, this results in the following example where the username double backslash has disappeared. "name":"Network Rule 1", "description":"Network Rule 1", "from":["internal"], "source":["any"], **"user":["domain\network_user1"]**, "to":["external"], "destination":["host.example.com","10.1.2.1"], "port":["8443","22"], "access":"allow", "time":"00:00:00-23:59:59", "notify":"yes" I'm guessing something is wrong with using echo to print the whole line, but what is a way to work around that? Thank you in advance.
Asked by vxla (11 rep)
Mar 28, 2024, 05:41 PM
Last activity: Mar 28, 2024, 06:00 PM