Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Find and delete a certain HEX and its following value in a file

perl, solved

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-13-2018
surfi surfi is offline
Registered User
 
Join Date: Feb 2018
Last Activity: 14 February 2018, 4:25 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question Find and delete a certain HEX and its following value in a file

Hello there,

I've been trying to do this half of the day and it's like I haven't come a single step further, so I hope you guys can help me with my problem:

I have a text file that contains strings that should not be there and which I want to delete automatically from the command line. The character string always consists of two characters, beginning with the hex value "01" (e. g."01 90").

My task is therefore:"search for HEX value 01 and delete this and the following HEX-value". However, I'm too stupid for this task...

Can anyone help me or give me a suggestion which command I need? I've tried tr and sed so far..
Sponsored Links
    #2  
Old 02-13-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 July 2018, 4:23 AM EDT
Location: Aachen, Germany
Posts: 13,069
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
Welcome to the forum.

A bit more information would be great, particularly an input sample, or, for your special problem, a hexdump (od -tx1c file) of it. And, your attempts, even though they failed, for analysis and discussion.
Sponsored Links
    #3  
Old 02-13-2018
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 16 July 2018, 10:38 PM EDT
Posts: 3,552
Thanks: 159
Thanked 1,267 Times in 1,161 Posts
You can try:

Code:
LC_ALL=C sed "s/[\x01].//g" text_file > fixed_text_file

Testing example:
Code:
$ printf "Test:%b%b\n" "\x1" "\x90" | od -c
0000000   T   e   s   t   : 001 220  \n
0000010

$ printf "Test:%b%b\n" "\x1" "\x90" | LC_ALL=C sed "s/[\x01].//g" | od -c
0000000   T   e   s   t   :  \n
0000006

The Following User Says Thank You to Chubler_XL For This Useful Post:
surfi (02-14-2018)
    #4  
Old 02-14-2018
surfi surfi is offline
Registered User
 
Join Date: Feb 2018
Last Activity: 14 February 2018, 4:25 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks, Chubler_XL. The example with sed didn't work (nothing happened actually), however, with perl it worked. So the final code was:

Code:
perl -pe "s/[\x01].//g" < text_file > fixed_text_file

Thank you very much
Sponsored Links
    #5  
Old 02-14-2018
abdulbadii abdulbadii is offline
Registered User
 
Join Date: Jan 2018
Last Activity: 23 April 2018, 1:31 AM EDT
Posts: 47
Thanks: 3
Thanked 7 Times in 7 Posts
Code:
sed -r 's/\b01\s+[0-9]{2}//g' YourFile

Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find and increment value in string of hex securegooner Shell Programming and Scripting 11 12-20-2017 09:02 AM
Find if file is 45 min old if yes delete kumar30213 Shell Programming and Scripting 3 03-18-2014 01:29 PM
Find and delete file previous to some date nnani Shell Programming and Scripting 6 09-11-2013 06:49 AM
After converting the hexstr to Hex and storing the Hex in a char* rvan Programming 1 08-09-2009 10:18 PM
find and delete a file in one command wewee UNIX for Dummies Questions & Answers 3 06-09-2008 12:22 PM



All times are GMT -4. The time now is 04:59 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?