There is \n
string in my file.
Contents of the file source.txt
is only one row with text (plus enter at end of first line):
I want to replace only substring \nconsisting of characters \\ and n
You can see \n
substring inside before "consisting" word. I want to replace this substring with substring \n
and some ident spaces. My script is in file script.sh
:
#!/bin/bash
ident=" "
rep_old="\n"
rep_new="\n$ident"
FILE=source.txt
while read line
do
echo -e "$line"
echo -e "NEW: ${line//$rep_old/$rep_new}"
done < $FILE
Actual output after call script.sh
from bash (my os is Windows):
I want to replace only substring nconsisting of characters \ and n
NEW: I wa
t to replace o
ly substri
g
co
sisti
g of characters \ a
d
But I want to replace only one \n
. I tried also use rep_old="\\n"
but without success. What is correct way to achieve this two variants of result?
1: I want to replace only substring \n consisting of characters \\ and n
2: I want to replace only substring
consisting of characters \\ and n
What I try based to yours answers:
A: rep_old="\\\\n"
A: result:
I want to replace only substring nconsisting of characters \ and n
NEW: I want to replace only substring nconsisting of characters \ and n