Created
August 30, 2019 14:31
-
-
Save richbs/ea7996eb6839eb2146191ad0afbdd293 to your computer and use it in GitHub Desktop.
Bash to copy and rename files from first line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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