Unix/Linux Go Back    


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

Shell Programming and Scripting


Tags
perl, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 6 Days Ago   -   Original Discussion by surfi
surfi's Unix or Linux Image
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
Unix or Linux 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 Unix and Linux 6 Days Ago   -   Original Discussion by surfi
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 February 2018, 4:26 AM EST
Location: Aachen, Germany
Posts: 12,138
Thanks: 366
Thanked 3,737 Times in 3,434 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 Unix and Linux 6 Days Ago   -   Original Discussion by surfi
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 19 February 2018, 9:57 PM EST
Posts: 3,462
Thanks: 151
Thanked 1,225 Times in 1,124 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 (6 Days Ago)
    #4  
Old Unix and Linux 6 Days Ago   -   Original Discussion by surfi
surfi's Unix or Linux Image
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 Linux
Sponsored Links
    #5  
Old Unix and Linux 5 Days Ago   -   Original Discussion by surfi
abdulbadii's Unix or Linux Image
abdulbadii abdulbadii is offline
Registered User
 
Join Date: Jan 2018
Last Activity: 20 February 2018, 3:54 AM EST
Posts: 31
Thanks: 3
Thanked 4 Times in 4 Posts


Code:
sed -r 's/\b01\s+[0-9]{2}//g' YourFile

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:02 AM
Find if file is 45 min old if yes delete kumar30213 Shell Programming and Scripting 3 03-18-2014 02:29 PM
Find and delete file previous to some date nnani Shell Programming and Scripting 6 09-11-2013 07:49 AM
After converting the hexstr to Hex and storing the Hex in a char* rvan Programming 1 08-09-2009 11:18 PM
find and delete a file in one command wewee UNIX for Dummies Questions & Answers 3 06-09-2008 01:22 PM



All times are GMT -4. The time now is 05:54 AM.