Skip to content

Instantly share code, notes, and snippets.

@richbs
Created August 30, 2019 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richbs/ea7996eb6839eb2146191ad0afbdd293 to your computer and use it in GitHub Desktop.
Save richbs/ea7996eb6839eb2146191ad0afbdd293 to your computer and use it in GitHub Desktop.
Bash to copy and rename files from first line
#!/bin/bash
mkdir -p out
for filename in *.txt; do
[ -e "$filename" ] || continue
outfile=out/$(head -n 1 "$filename" | tr -d '\r?\n' | tr '/' ' ').txt
[ -e "$outfile" ] && outfile=out/$(head -n 1 "$filename" | tr -d '\r?\n' | tr '/' ' ')$(gdate +%s%N).txt
tail -n +2 "$filename" > "$outfile"
touch -r "$filename" "$outfile"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment