Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Align-columns/UNIX-Shell/align-columns-1.sh
Normal file
37
Task/Align-columns/UNIX-Shell/align-columns-1.sh
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
cat <<EOF_OUTER > just-nocenter.sh
|
||||
#!/bin/sh
|
||||
|
||||
td() {
|
||||
cat <<'EOF'
|
||||
Given$a$text$file$of$many$lines,$where$fields$within$a$line$
|
||||
are$delineated$by$a$single$'dollar'$character,$write$a$program
|
||||
that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$
|
||||
column$are$separated$by$at$least$one$space.
|
||||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified,$or$center$justified$within$its$column.
|
||||
EOF
|
||||
}
|
||||
|
||||
rows=$( td | wc -l )
|
||||
|
||||
# get the number of fields
|
||||
fields=$(td | rs -c'$' -g1 -h | awk '{print $2}')
|
||||
|
||||
# get the max of the value widths
|
||||
cwidth=$(td | rs -c'$' -g1 -w1 2>/dev/null | awk 'BEGIN{w=0}{if(length>w){w=length}}END{print w}')
|
||||
|
||||
# compute the minimum line width for the columns
|
||||
lwidth=$(( (1 + cwidth) * fields ))
|
||||
|
||||
# left adjusted columns
|
||||
td | rs -c'$' -g1 -zn -w$lwidth
|
||||
|
||||
echo ""
|
||||
|
||||
# right adjusted columns
|
||||
td | rs -c'$' -g1 -znj -w$lwidth
|
||||
|
||||
echo ""
|
||||
|
||||
exit
|
||||
EOF_OUTER
|
||||
14
Task/Align-columns/UNIX-Shell/align-columns-2.sh
Normal file
14
Task/Align-columns/UNIX-Shell/align-columns-2.sh
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
$ ./just-nocenter.sh
|
||||
Given a text file of many lines, where fields within a line
|
||||
are delineated by a single 'dollar' character, write a program
|
||||
that aligns each column of fields by ensuring that words in each
|
||||
column are separated by at least one space.
|
||||
Further, allow for each word in a column to be either left
|
||||
justified, right justified, or center justified within its column.
|
||||
|
||||
Given a text file of many lines, where fields within a line
|
||||
are delineated by a single 'dollar' character, write a program
|
||||
that aligns each column of fields by ensuring that words in each
|
||||
column are separated by at least one space.
|
||||
Further, allow for each word in a column to be either left
|
||||
justified, right justified, or center justified within its column.
|
||||
1
Task/Align-columns/UNIX-Shell/align-columns-3.sh
Normal file
1
Task/Align-columns/UNIX-Shell/align-columns-3.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
tr '$' ' ' | column -t
|
||||
Loading…
Add table
Add a link
Reference in a new issue