File: sort_api.sh

package info (click to toggle)
android-platform-frameworks-base 1%3A10.0.0%2Br36-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 321,788 kB
  • sloc: java: 962,234; cpp: 274,314; xml: 242,770; python: 5,060; sh: 1,432; ansic: 494; makefile: 47; sed: 19
file content (26 lines) | stat: -rwxr-xr-x 560 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
set -e
if [ -z "$1" ]; then
  source_list=/dev/stdin
  dest_list=/dev/stdout
else
  source_list="$1"
  dest_list="$1"
fi
# Load the file
readarray A < "$source_list"
# Sort
IFS=$'\n'
# Stash away comments
C=( $(grep -E '^#' <<< "${A[*]}" || :) )
A=( $(grep -v -E '^#' <<< "${A[*]}" || :) )
# Sort entries
A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") )
A=( $(uniq <<< "${A[*]}") )
# Concatenate comments and entries
A=( ${C[*]} ${A[*]} )
unset IFS
# Dump array back into the file
if [ ${#A[@]} -ne 0 ]; then
  printf '%s\n' "${A[@]}" > "$dest_list"
fi