replace skip with more general drop

This commit is contained in:
Neale Pickett 2017-08-09 16:10:40 +00:00
parent bc27cf7b32
commit c4f4a28867
3 changed files with 53 additions and 48 deletions

View File

@ -75,17 +75,21 @@ The "-x" option treats values as hex.
cbcbcb cbcbcb
### skip: discard initial octets ### drop: discard octets
Throws away some initial octets from stdin, Throws away some octets from stdin,
and sends the rest to stdout. and sends the rest to stdout.
You could use `dd` for the same purpose. You could use `dd` for the same purpose.
$ echo abcdefgh | dd skip=5 bs=1 status=none $ echo 01234567 | drop 0 3
fgh 34567
$ echo abcdefgh | skip 5 $ echo 01234567 | drop 4 7
fgh 01237
$ echo 01234567 | drop 4 6
012367
$ echo 01234567 | drop 3 9999
012
### pcat: print text representation of pcap file ### pcat: print text representation of pcap file

43
drop.c Normal file
View File

@ -0,0 +1,43 @@
/*
* drop octets -- 2017 Neale Pickett <zephyr@dirtbags.net>
*
* This file is in the public domain. I make no promises about the functionality
* of this program.
*/
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
unsigned long int start;
unsigned long int end;
unsigned long int pos;
if (3 == argc) {
start = strtoul(argv[1], NULL, 0);
end = strtoul(argv[2], NULL, 0);
} else {
fprintf(stderr, "Usage: %s start end\n", argv[0]);
fprintf(stderr, "\n");
fprintf(stderr, "Drops octets from input\n");
return 1;
}
for (pos = 0; ; pos += 1) {
int c = getchar();
if (EOF == c) {
break;
}
if ((start <= pos) && (pos < end)) {
/* drop */
} else {
putchar(c);
}
}
return 0;
}

42
skip.c
View File

@ -1,42 +0,0 @@
/*
* skip octets -- 2017 Neale Pickett <zephyr@dirtbags.net>
*
* This file is in the public domain. I make no promises about the functionality
* of this program.
*/
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
long int count;
if (argc != 2) {
fprintf(stderr, "Usage: %s count\n", argv[0]);
return 1;
}
count = strtol(argv[1], NULL, 0);
/* Throw away count octets */
for (; count > 0; count -= 1) {
int c = getchar();
if (EOF == c) {
break;
}
}
/* Spit out the rest */
while (1) {
int c = getchar();
if (EOF == c) {
break;
}
putchar(c);
}
return 0;
}