Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add hex value to text file

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
FR
Hello,

I have a txt file like this text.txt :
Line1
Line2
Line3
I need to add X’03320000’ (as hex value) at the begining of each line (it represent the size of the line - in my case each line is the same size - which should make things easier).

Has anyone an idea ?

Thank you !
 
A few things a tried (no success) :

1.
RDW="\x03\x32\x00\x00"
LINE="t"
echo "$RDW$LINE" > result.txt
=> adds \x03\x32\x00\x00t (all ascii) in result.txt

2.
a=`cat hexfile` (or a=$(<hexfile))
sed `s/^/"${a}";/` < test.txt > result.txt
where hexfile is a file with the hex value I need (created using UltraEdit).

=> error messages : s/^/^C2: not found [No such file or directory]
: /: cannot execute [Is a directory]

3.a=`cat hexfile` (or a=$(<hexfile))
awk `{ printf ${a}";%s\n", $0 }` < test.txt > result.txt

=> error message : `{' unmatched

...[evil]
 
What about this ?
awk 'BEGIN{getline a<"hexfile"}{print a";"$0}' test.txt >result.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you ... but it did not work ...
BEGIN: not found [No such file or directory]

I tried without the BEGIN, and I get the same errors as before (`{' unmatched).


 
USe single quotes instead of backquotes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top