Long message ends up empty at destination - gammu

Why is the following (decoded) message cut correctly at the 160th character, as expected:
00000000010000000002000000000300000000040000000005000000000600000000070000000008000000000900000000100000000011000000001200000000130000000014000000001500000000160000000017000000001800000000190000000020
The destination receives:
0000000001000000000200000000030000000004000000000500000000060000000007000000000800000000090000000010000000001100000000120000000013000000001400000000150000000016
While the following message is just ending up empty at the destination:
[aaaaaa] bbbbbbbb | cccc_ccc
\_ dd (eeeeeeee)
\_ fff ff - f.fff ffffff ffffffff ffff ff ffffffff.ffff.ff ffff 389
\_ 2020-07-07 20:10:27 +0200
\_ ggggg ggggg ggggggggg GGG gg gggggggg g ggggg gg gggggggg ggg gggg gggg ggg ggggggg:
hhhhh Y44wCg6vu8m6CeG5ZB8MA2nif9l0nG7/Nceec5NA7UjZO+OKHOAjCy5hdeAdt+WVD2U=|n
I'm simply inserting it into outbox. I know I should use outbox_multipart for longer messages, but that is not the question. I am wondering why the second message is ending up empty at the destination while the first is just cut off.
(Gammu 1.39 on SLES15)

Related

Display and format aligned binary data using bash

I have a binary file that stores a collection of C structs, e.g.
typedef struct{
uint8_t field1;
uint16_t field2;
uint32_t field3;
}example;
I would like to dump the file aligned, i.e. have one instance per line. I don't really need to have space separated values for each field, this would be enough for example :
# field 1 == 0xaa, field 2 == 0xbbcc, field 3 == 0x00112233
$ command my_file.bin
aabbcc00112233 # output is repeated for each struct
Considering the example above, file content is the following :
$ hexdump my_file.bin
0000000 ccaa 33bb 1122 aa00 bbcc 2233 0011 ccaa
0000010 33bb 1122 aa00 bbcc 2233 0011 ccaa 33bb
0000020 1122 aa00 bbcc 2233 0011 ccaa 33bb 1122
0000030 aa00 bbcc 2233 0011 ccaa 33bb 1122 aa00
0000040 bbcc 2233 0011
0000046
od is a perfect fit when the struct is a multiple of 4 (e.g. od -tx --width=8), but does not work properly in this example where the width is 7 bytes. Is it possible in bash ?
Tell od to print 7 bytes per line, each individually, and get rid of spaces using tr.
$ od -An -v -tx1 -w7 file | tr -d ' '
aabbcc00112233
...
Note that this is only good for big-endian inputs.

How to replace columns (matching pattern) using awk?

I am trying to use awk to edit files but I cant manage to do it without creating intermediate files.
Basicaly I want to search using column 1 in file2 and file3 and so on, and replace the 2nd column for matching 1st column lines. (note that file2 and file3 may contain other stuff)
I have
File1.txt
aaa 111
aaa 222
bbb 333
bbb 444
File2.txt
zzz zzz
aaa 999
zzz zzz
aaa 888
File3.txt
bbb 000
bbb 001
yyy yyy
yyy yyy
Desired output
aaa 999
aaa 888
bbb 000
bbb 001
this does what you specified but I guess there are many edge cases not covered.
$ awk 'NR==FNR{a[$1]; next} $1 in a' file{1..3}
aaa 999
aaa 888
bbb 000
bbb 001

How to find any decrement in the column?

I am trying to find out the decrements in a column and if found then print the last highest value.
For example:
From 111 to 445 there is a continous increment in the column.But 333 is less then the number before it.
111 aaa
112 aaa
112 aaa
113 sdf
115 aaa
222 ddd
333 sss
333 sss
444 sss
445 sss
333 aaa<<<<<<this is less then the number above it (445)
If any such scenario is found then print 445 sss
Like this, for example:
$ awk '{if (before>$1) {print before_line}} {before=$1; before_line=$0}' a
445 sss
What is it doing? Check the variable before and compare its value with the current. In case it is bigger, print the line.
It works for many cases as well:
$ cat a
111 aaa
112 aaa
112 aaa
113 sdf
115 aaa <--- this
15 aaa
222 ddd
333 sss
333 sss
444 sss
445 sss <--- this
333 aaa
$ awk '{if (before>$1) {print before_line}} {before=$1; before_line=$0}' a
115 aaa
445 sss
Store each number in a single variable called prevNumber then when you come to print the next one do a check e.g. if (newNumber < prevNumber) print prevNumber;
dont really know what language you are using
You can say:
awk '$1 > max {max=$1; maxline=$0}; END{ print maxline}' inputfile
For your input, it'd print:
445 sss

bash sequence 00 01 ... 10

in bash, with
$ echo {1..10}
1 2 3 4 5 6 7 8 9 10
I can get a numbers sequence, but in some case I need
01 02 03 ... 10
how I can get this ?
and how I can get ?
001 002 ... 010 011 .. 100
This will work in any shell on a machine that has coreutils installed (thanks commenters for correcting me):
seq -w 1 10
and
seq -w 1 100
Explanation:
the option -w will:
Equalize the widths of all numbers by padding with zeros as necessary.
seq [-w] [-f format] [-s string] [-t string] [first [incr]] last
prints a sequence of numbers, one per line (default), from
first (default 1), to near last as possible, in increments of incr (default
1). When first is larger than last the default incr is -1
use seq command with -f parameter, try:
seq -f "%02g" 0 10
results:
00
01
02
03
04
05
06
07
08
09
10
seq -f "%03g" 0 10
results:
000
001
002
003
004
005
006
007
008
009
010
printf "%02d " {1..10} ; echo
Output:
01 02 03 04 05 06 07 08 09 10
Similarly:
printf "%03d " {1..100} ; echo
In more recent versions of bash, simply:
echo {01..10}
And:
echo {001..100}
for i in {01..99}; do
echo $i
done
will return :
01
02
03
04
05
06
07
08
09
10
...
Replacing 01 with 001 and 99 with 999 or 100 will do what you expect also.
$ printf "%02d " {0..10}; echo
00 01 02 03 04 05 06 07 08 09 10
$ printf "%03d " {0..100}; echo
000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100
Just vary the field width in the format string (2 and 3 in this case) and of course the brace expansion range. The echo is there just for cosmetic purposes, since the format string does not contain a newline itself.
printf is a shell builtin, but you likely also have a version from coreutils installed, which can be used in-place.
awk only:
awk 'BEGIN { for (i=0; i<10; i++) printf("%02d ", i) }'
The following will work in bash
echo {01..10}
**EDIT seeing the answers around me I just wanted to add this, in the case we're talking about commands that will work under any terminal
yes | head -n 100 | awk '{printf( "%03d ", NR )}' ##for 001...100
or
yes | head -n 10 | awk '{printf( "%03d ", NR )}' ##for 01..10
echo 0{0..9}
You can get: 00 01 02 03 04 05 06 07 08 09
echo 0{0..9} 1{0..9}
You can get: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
echo 00{0..9} 0{10..99}
You can get 001 .. 099
There are so many ways to do this! My personal favorite is:
yes | grep y | sed 100q | awk '{printf( "%03d ", NR )}'; echo
Clearly, neither the sed nor the grep are necessary (the grep being far more trivial, since if you omit the sed you need to change the awk), but they contribute to the overall satisfaction of the solution! The final echo is not really necessary either, but it's always nice to have a trailing newline.
Another nice option is:
yes | nl -ba | tr ' ' 0 | sed 100q | cut -b 4-6
Or (less absurdly):
yes '' | sed ${top-100}q | nl -ba -w ${width-3} -n rz
as commented by favoretti, seq is your friend.
But there is a caveat:
seq -w uses the second argument to set the format it will use.
Thus, the command seq -w 1 9 will print the sequence 1 2 3 4 5 6 7 8 9
To print the sequence 01 .. 09 you need to do the following:
seq -w 1 09
Or for clarities sake use the same format on both ends, for instance:
seq -w 000 010 for the series 001 002 003 ... 010
And you can also use a step argument that also works in reverse:
seq -w 10 -1 01' for 10,09,08...01 orseq -w 01 2 10` for 01,03,05,07,09

computer basics problem

hi everybody can anyone tell me answer of this question ?
i created a simple txt file. it contain only two words and the words are hello word according to i studied computer uses ascii code to store the text on disk or memory .In ascii code each letter or symbol is represented by one byte or in simple words one byte is used to store a symbol.
Now the problem is this when ever i saw the size of file it shows 11 byte I understand 9 byte for words one byte for space makes the total of 10 then why it is showing 11 byte size .i tried different things such as changing the name of file saving it with shortest name possible or longest name possible but it did not change the total storage
so can any body explain why it is happening? i tried this thing over window or Linux(Ubuntu.centos) system result is same.
pax> echo hello word >outfile.txt
pax> ls -al outfile.txt
-rw-r--r-- 1 pax pax 11 2010-11-19 15:34 outfile.txt
pax> od -xcb outfile.txt
0000000 6568 6c6c 206f 6f77 6472 000a
h e l l o w o r d \n
150 145 154 154 157 040 167 157 162 144 012
pax> hd outfile.txt
00000000 68 65 6c 6c 6f 20 77 6f 72 64 0a |hello word.|
0000000b
As per above, you're storing "hello word" and the newline character. That's 11 characters in total. If you don't want the newline, you can use something like the -n option of echo (which doesn't add the newline):
pax> echo -n hello word >outfile.txt
pax> ls -al outfile.txt
-rw-r--r-- 1 pax pax 10 2010-11-19 15:36 outfile.txt
pax> od -xcb outfile.txt
0000000 6568 6c6c 206f 6f77 6472
h e l l o w o r d
150 145 154 154 157 040 167 157 162 144
pax> hd outfile.txt
00000000 68 65 6c 6c 6f 20 77 6f 72 64 |hello word|
0000000a
If you want to see the content of the file you can perform an octal dump of it using the "od" command under linux "od ". Most probably what you will see is a CR (carriage return) and a LN (linefeed).
The name of the file has nothing to do with his size.
Luis
Did you a new line in the text file (\n)? Just because this character cannot be seen does not mean it is not there.

Resources