Friday, 4 February 2022

How to use GNU Stream Editor (sed)

sed is a Unix tool, a GNU stream editor.
How to remove hex characters from the beginning of the file?
Example: The following command removes a BOM Unicode character (xEFBBBF) from the beginning of the file. Removal is done in-place:

$ sed -i '1s/^\xef\xbb\xbf//' commands.sql 
1s/ - only search the first line, other lines are unaffected
^ - the beginning of the line (only match at the start of the line)
\xEF\xBB\xBF - bytes to be removed - UTF-8 BOM (escaped hex string)
// - replace with empty string
If we wanted to keep the original file intact and create a new file, with all the changes:

$ sed '1s/^\xef\xbb\xbf//' < commands.sql > new_commands.sql


1 comment:

Unknown said...

A few months ago, I felt so depressed, I got frustrated with bad credits, but then I contacted HACK VANISH by phone: +1 (747) 293-8514 and email: HACK VANISH (@) GMAIL. COM. I found out about hack vanish services through positive reviews read on some credit blogs, in a blink of an eye this great hacker restored my credit score from 509 to 784 in all 3 major credit bureaus, they got removed evictions and foreclosures, my LexisNexis and Chex system was repaired respectively, a few days later I received an email confirming the approval of my mortgage loan, it was quite surprising because I never thought it was possible. Today, I can confidently say that 2021 was a banner year for my husband and I as we now own a new house and a new SUV courtesy of HACK VANISH, I would definitely recommend him to anyone in need of a genuine Hacker.