| | |
Reading a file containing escaped sequences
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi,
I've a file having some regular expressions.
e.g. cat regex.txt
[\t\n]
abc.*pqr
If I write a small bash script as below,
while read line
do
echo -E "$line"
done < regex.txt
even with -E switch passed to echo the output is
[tn]
abc.*pqr
So the backslashes have vanished in the first regular expression.
Is there a way to retain all backslashed escape sequences
while reading a file using the while loop ?
Thanks,
Mahendra
I've a file having some regular expressions.
e.g. cat regex.txt
[\t\n]
abc.*pqr
If I write a small bash script as below,
while read line
do
echo -E "$line"
done < regex.txt
even with -E switch passed to echo the output is
[tn]
abc.*pqr
So the backslashes have vanished in the first regular expression.
Is there a way to retain all backslashed escape sequences
while reading a file using the while loop ?
Thanks,
Mahendra
Shell Scripting Syntax (Toggle Plain Text)
while IFS= read -r;do printf '%s\n' "$REPLY" done<regex.txt
•
•
Join Date: Mar 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
while IFS= read -r;do printf '%s\n' "$REPLY" done<regex.txt
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: A simple bash script not working as expected
- Next Thread: Help! extract picture from a multi-page pdf/ps file
Views: 528 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





