Shell Read Config


原文链接: Shell Read Config
file="$1"
FS_OLD=$IFS
IFS="\n"
while read line || [[ -n "$line" ]]
do
    IFS=",\n"
    read -a array <<< "$line"
    echo $((array[0] % array[1]))
    IFS="\n"
done < "$file"
IFS=$IFS_OLD

  1. sh ls download/*.html | while read LINE; do perl parseDocs.pl $LINE 2>/dev/null done


IFS='|' read -a split_input <<< "$1"

echo "Enter filename to parse: "
read FILE
 [ -n $FILE ] || FILE=backend.conf
# IFS="$DELIM"
while IFS=', \t' read -r name port ssh_host ssh_port ssh_user ssh_password mysql_host mysql_user mysql_password redis_host redis_password; do
    echo
    echo name          :   $name
    echo port          :   $port
    echo ssh_host      :   $ssh_host
    echo ssh_port      :   $ssh_port
    echo ssh_user      :   $ssh_user
    echo ssh_password  :   $ssh_password
    echo mysql_host    :   $mysql_host
    echo mysql_user    :   $mysql_user
    echo mysql_password:   $mysql_password
    echo redis_host    :   $redis_host
    echo redis_password:   $redis_password
done <"$FILE"

config
`name port ssh_host ssh_port ssh_user ssh_password mysql_host mysql_user mysql_password redis_host redis_password`
  1. 从命令行读取数据
    sh while read line do echo echo "redsocks {" IFS=, read local_ip local_port proxy_ip proxy_port type parse_host <<< $line echo ' ' local_ip = $local_ip\; echo ' ' local_port = $local_port\; echo ' ' ip = $proxy_ip\; echo ' ' port = $proxy_port\; echo ' ' type = $type\; if [ $parse_host -a $parse_host != None ] then echo ' ' parse_host = $parse_host\; fi echo "}" done

echo "WARNING: this script does not work yet"

parse_ldd () {
	ldd $1|grep -v linux|sed 's/.\+ => \(.\+\) (.\+/\1/'
}
parse_file () {
	while read stuff
	do
		parse_ldd $stuff > $2
	done < $1
}
parse_recurse ()
{
	>result_tmp
	parse_ldd $1 > tmp1
	while [ "$(cat tmp1 | grep -v '^ +$')" != "" ]
	do cat tmp1 >> result_tmp
		parse_file tmp1 tmp2
		mv tmp2 tmp1
	done
	cat result_tmp|sort|uniq > result
	rm result_tmp
}
parse_recurse $1
cat result

html_parser.sh

#!/bin/bash
# Input must add '<' otherwise the last tag is missed
parse() {
	while IFS=$'>' read -d $'<' tag text; do
		tag="$(printf '%s' "$tag" | sed -E 's#^ +| +$##g')"
		echo "ent '$tag', text '$text'";
	done
}

if [ -z "$1" ]; then
	text="";
	while read line; do
		text=$text$line;
	done
	(echo "$text"; echo '<') | parse;
else
	(cat "$1"; echo '<') | parse;
fi
`