Skip to content

Instantly share code, notes, and snippets.

@federkamm
Created May 17, 2024 01:03
Show Gist options
  • Save federkamm/95a329bece85264b7bc716d8061c2df4 to your computer and use it in GitHub Desktop.
Save federkamm/95a329bece85264b7bc716d8061c2df4 to your computer and use it in GitHub Desktop.
GNU parallel header line with comment character
#!/usr/bin/env bash
# metadata file in the format
cat >meta.tmp <<EOF
# filename lat lon alt
file.jpg 1.0 2.0 3.0
EOF
# where the title line starts with a comment character (#) and there are some additional
# fields actually even before the relevant ones (lat lon alt) in the file
# the following command is off by one header due to the presence
# of the comment character:
parallel --dry-run -C' ' --header : exiftool -GPSLatitude\\\*={lat} {filename} <meta.tmp
# results in: "exiftool -GPSLatitude\\\*=2.0 1.0"
# according to GNU parallel man page the regex for --header should match the header, therefore
parallel --dry-run -C' ' --header '\w.*\n' exiftool -GPSLatitude\\\*={lat} {filename} <meta.tmp
# should work but apparently the regex only matches the line in which the header appears
# as a workaround don't match the space after the comment character as column separator:
parallel --dry-run -C'(*nlb:#) ' --header : exiftool -GPSLatitude\\\*={lat} {#\ filename} <meta.tmp
# results in: "exiftool -GPSLatitude\\\*=1.0 file.jpg"
# note that the comment character will be part of the first column header and the space
# must be escaped: "#\ filename"!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment