How can I use aliased commands with xargs?

Aliases are shell-specific – in this case, most likely bash-specific. To execute an alias, you need to execute bash, but aliases are only loaded for interactive shells (more precisely, .bashrc will only be read for an interactive shell). bash -i runs an interactive shell (and sources .bashrc). bash -c cmd runs cmd. Put them together: … Read more

Understanding the UNIX command xargs

In general xargs is used like this prog | xargs utility where prog is expected to output one or more newline/space separated results. The trick is that xargs does not necessarily call utility once for each result, instead it splits the results into sublists and calls utility for every sublist. If you want to force … Read more

xargs split at newlines not spaces

Try: printf %b ‘ac s\nbc s\ncc s\n’ | xargs -d ‘\n’ bash /tmp/test.sh You neglected to quote the \n passed to -d, which means that just n rather than \n was passed to xargs as the delimiter – the shell “ate” the \ (when the shell parses an unquoted string, \ functions as an escape … Read more

Using grep to search for hex strings in a file

This seems to work for me: LANG=C grep –only-matching –byte-offset –binary –text –perl-regexp “<\x-hex pattern>” <file> short form: LANG=C grep -obUaP “<\x-hex pattern>” <file> Example: LANG=C grep -obUaP “\x01\x02” /bin/grep Output (cygwin binary): 153: <\x01\x02> 33210: <\x01\x02> 53453: <\x01\x02> So you can grep this again to extract offsets. But don’t forget to use binary mode … Read more

tech