Advertisement
Hashim

For loop to sort multiple files with output file for each

Sep 15th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  1. for file in *.txt;
  2. do
  3. [ -f "$file" ] && printf 'Processing %s\n' "$file"
  4. [[ "$file" == *?.* ]] && # If file has a period after at least one character; filters out .bashrc and similar
  5. file1="./${file%.*}_sorted.${file##*.}" || # For files with extensions ($file becomes file1)
  6. file1="${file}_sorted"
  7. # For files without extensions ($file becomes file1)
  8. LC_ALL=C sort -u "$file" > "./$file1"
  9. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement