
Untitled
By: a guest on
Jun 10th, 2012 | syntax:
None | size: 0.89 KB | hits: 18 | expires: Never
Bash Sorting STDIN
#!/bin/bash
inp=0 echo "Which filename for strings?"
read strg
touch $strg
echo "Which filename for nums?"
read nums
touch $nums
echo "Which filename for alphanumerics?"
read alphanums
touch $alphanums
while [ "$inp" != "quit" ]
do
echo "Input: "
read inp
echo $inp | grep -o '<[a-zA-Z]+>' > $strg
echo $inp | grep -o '<[0-9]>' > $nums
echo $inp | grep -o -E '<[0-9]{2,}>' > $nums
done
$ grep -o '<[a-zA-Z]+>' sorting_input
this
is
a
string
containing
words
single
digits
as
in
and
as
well
$ grep -o '<[0-9]>' sorting_input
1
2
$ grep -o -E '<[0-9]{2,}>' sorting_input
42
1066
<input_file strings -1 -a | tee chars_and_strings.txt |
grep "^[A-Za-z0-9][A-Za-z0-9]*$" | tee alphanum.txt |
grep "^[0-9][0-9]*$" > numonly.txt
#!/bin/bash
cat > temp
grep pattern1 > file1
grep pattern2 > file2
grep pattern3 > file3
rm -f temp
cat file_to_process | ./script.sh