|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[Script] Conditions on parsing file
Hello, I open a new POST, i consider that this is resolved http://www.unix.com/shell-programmin...nt-script.html But i wish improve it. In case 1, I would like to test the input file $1. If $1 exist with no parameters but only comments, then send a message "Please..." I tried somethings but no results. Can you help me ? Code:
#!/bin/bash
# set -vx
f1() {
echo $1 $2 $3 $4
}
case $# in
0) echo -e "# comment1\n# comment2" > list_file
read -p "Please fill in this list_file: "
echo $REPLY
;;
1) [ -f "$1" ] || exit
grep -v '^#' "$1" |
while read arg1 arg2 arg3 arg4
do f1 $arg1 $arg2 $arg3 $arg4
done
;;
4) echo -e "# comment1\n# comment2" > list_file
echo $1 $2 $3 $4 >> list_file
;;
5) echo -e "# comment1\n# comment2" > $1
f1 $2 $3 $4 $5 >> "$1"
;;
*) echo "error msg"; exit
esacHave a nice day. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
if [ -f "$1" ] then ... else ... fi |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks ![]() It's OK Code:
#!/bin/bash
# set -vx
f1() {
echo $1 $2 $3 $4
}
case $# in
0) echo -e "# comment1\n# comment2" > list_file
read -p "Please fill in this list_file: "
echo $REPLY
;;
1) if [ ! -f "$1" ]
then > $1 && echo -e "# comment1\n# comment2" > $1
read -p "Please fill in "$1": "
echo $REPLY
else
if [ -f "$1" -a $(grep -v '^#' "$1" | wc -l ) -ne 0 ]
then
grep -v '^#' "$1" |
while read arg1 arg2 arg3 arg4
do f1 $arg1 $arg2 $arg3 $arg4
done
else
read -p "Please fill in $1 : "
echo $REPLY
fi
fi
;;
4) echo -e "# comment1\n# comment2" > list_file
echo $1 $2 $3 $4 >> list_file
;;
5) echo -e "# comment1\n# comment2" > $1
f1 $2 $3 $4 $5 >> "$1"
;;
*) echo "error msg"; exit
esac |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script for Parsing Log File | Winsarc | Shell Programming and Scripting | 8 | 03-24-2011 11:12 AM |
| Parsing file in perl script | maverick.usb | Shell Programming and Scripting | 2 | 04-09-2010 10:17 AM |
| parsing data for certain conditions | PAW | Shell Programming and Scripting | 5 | 06-18-2009 09:10 AM |
| Script for parsing details in a log file to a seperate file | pingnagan | UNIX for Dummies Questions & Answers | 2 | 11-13-2008 11:21 AM |
| Parsing a file in Shell Script | sendhilmani123 | Shell Programming and Scripting | 4 | 11-30-2006 01:29 AM |
|
|