LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-26-2009, 03:27 AM   #1
Kadabra
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
Question batch hex editing


I need to batch edit a bunch of files in hexadecimal format. To be precise, I need to strip some zeros at the end of those files. Any ideas how I could do that?
 
Old 03-26-2009, 03:47 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
If you dont care about the \x00 anywhere else in the file:

Code:
echo -e -n "\x00AdmiralBeotch\x00" | tr -d '\0' | hexdump -C
 
Old 03-26-2009, 04:05 AM   #3
Kadabra
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Admiral Beotch View Post
If you dont care about the \x00 anywhere else in the file:

Code:
echo -e -n "\x00AdmiralBeotch\x00" | tr -d '\0' | hexdump -C
The problem is that I do care about the other zeros and I need to strip only those at the very end of the file.
 
Old 03-26-2009, 04:52 AM   #4
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Code:
echo -e -n "\x00test\x00\n\x00AdmiralBeotch\x00\x00" | sed '$s/\x00*$//;'  | hexdump -C
 
Old 03-26-2009, 05:03 AM   #5
Kadabra
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Admiral Beotch View Post
Code:
echo -e -n "\x00test\x00\n\x00AdmiralBeotch\x00\x00" | sed '$s/\x00*$//;'  | hexdump -C
Thanks, seems to be just what I needed
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] ASCII to HEX and hex to ascii ////// Programming 17 05-08-2018 09:55 PM
Batch file editing Braynid Linux - Software 2 09-18-2008 04:26 AM
Hex output of a hex/ascii input string mlewis Programming 35 04-10-2008 12:05 PM
Hex socks Linux - General 4 02-17-2005 12:05 PM
batch editing multiple lines statmobile Programming 8 09-16-2004 08:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration