Replacing Control Character in sed
This can be done through cat
with the -v
(equivalently --show-nonprinting
options and piping this into sed
).
If the control character the start of heading (SOH) character (CTRL+A / ASCII 1), and we want to replace it with a tab, we would do the following:
cat -v file | sed 's/\^A/\t/g' > out
cat -v
would replace the SOH character with ^A, which would then be matched and replaced in sed
.
How to remove CTRL-A characters from file using SED?
to reproduce "^A" simply press Ctrl-v Ctrl-a this will reproduce the ^A in the file
sed -i -e 's/^A/BLAH/g' testfile
the ^A
in that line is the result of me pressing Ctrl-v Ctrl-a
Replace control characters with sed
There are no control characters. Just echo -e
to display this string:
s='Rating..........Red\nAlert.Name......High Update Response Time\nManaged.Object..D0P~ABAP~sap00d0p_D0P_48'
echo -e "$s"
Rating..........Red
Alert.Name......High Update Response Time
Managed.Object..D0P~ABAP~sap00d0p_D0P_48
sed remove a special control character from many files
POSIX sed doesn't handle NUL in input but GNU sed can with hex escape:
find . -name '*.html' -type f -exec sed -i 's/\x0//g' '{}' +
Replace text with special characters using sed
It's generally safer, and therefore often better, to use a JSON-aware tool rather than sed
when editing JSON. Using jq, one possibility would be:
jq --arg name "$name" --arg newvalue "$newvalue" '
.Changes[0].ResourceRecordSet |=
(.NAME=$name
| .ResourceRecords[0].Value = $newvalue)' <<< "$rssample"
A free-form approach
jq --arg name "$name" --arg newvalue "$newvalue" '
walk(if type == "object"
then if has("NAME") then .NAME=$name else . end
| if has("Value") then .Value = $newvalue else . end
else . end)' <<< "$rssample"
sed to replace non-printable character with printable character
Sed should recognise special characters:
sed -e 's/\x0b/ /g'
Related Topics
Negate If Condition in Bash Script
Grep Inside All Files Created Within Date Range
How to Convert Yyyymmddhhmmss to a Date Readable by 'Date'
Removing Part of a Filename for Multiple Files on Linux
Why Percent Signs (%) Do Not Work in Crontab
Unix: How to Delete Files Listed in a File
Why Doesn't Linux Use the Hardware Context Switch via the Tss
How Does Pthread Implemented in Linux Kernel 3.2
Pthread Mutex Lock Unlock by Different Threads
Why Does Printf Overwrite the Ecx Register
Why Doesn't "Total" from Ls -L Add Up to Total File Sizes Listed
How to Program Linux .Dts Device Tree Files
How to Reference Files Relative to Application Root in Node.Js
Gem5 Syscall Emulation Arm C Hello World Fails with "Fatal: Syscall Gettid (#224) Unimplemented"