I have an input file in the following form:
something here
somethingElseHere^[%-somestuff here
^[%-somestuff here
Note that ^[
is the escape character \x1b
.
So what I'm trying to do is delete everything on the file after the first ^[
occurrence, in a bash script, so I should end up with something like this:
something here
somethingElseHere
My solution was: awk -F "\x1b" {'print $1'}
but this is giving this as an output:
something here
somethingElseHere
(empty line here)
So it's adding an extra empty line after the last one. Still if I delete it manually I get an extra byte. I made a C++ program which reads the file until the \x1b
character and writes all the read characters in a separate file but with AWK, after deleting the extra line, I still get 1 byte more than doing it with C++.
Edit:
maybe it's the EOL character that gets added when using AWK? I don't add it when using the C++ program.
UPDATE:
I've just tried some of the commands, and most of them work if I open them in vi
, but still they have an extra byte and I can't figure out where it comes from.
$hexdump -x file1
0000000 4329 706f 7279 6769 7468 6328 2029 3931
0000010 3939 4d20 6369 6f72 6f73 7466 4320 726f
0000020 6f70 6172 6974 6e6f 610a 6362 6564 6766
0000030 6968 6b6a 6d6c 6f6e 7170 7372 7574 7776
0000040 7978 534d 5020 4c43 4c58 6f46 746e 3020
0000050 3130 a8f8 4955 0a42
0000058
$hexdump -x file2
0000000 4329 706f 7279 6769 7468 6328 2029 3931
0000010 3939 4d20 6369 6f72 6f73 7466 4320 726f
0000020 6f70 6172 6974 6e6f 610a 6362 6564 6766
0000030 6968 6b6a 6d6c 6f6e 7170 7372 7574 7776
0000040 7978 534d 5020 4c43 4c58 6f46 746e 3020
0000050 3130 a8f8 4955 0042
0000057
In file1, which is the one I'm generating with bash, it adds an extra 0x0a
(new line character).
awk -F "\x1b" '{print $1} NF > 1 {quit}'
?NF > 1 {quit}
it didn't work either.printf "%s", $1
to print without a new line.exit
, notquit