Hi all,
It's my first post on forum - saying HELLO
I have a simple script and would like to improve it.
When [user] in terminal writing correct file name then designed file making grep, etc.But if [user] writing wrong file name then warning should appear in terminal.
This script doesn't work properly. Can you tell me why, please
Code:
#!/bin/bash
##############################################
#Script is taking C,E,V records from P1 file
#
#############################################
#Direction of P1 file
P1_DIR='/home/sprint/Desktop/jacek/test/'
CEV_DIR='/home/sprint/Desktop/jacek/test/cev/'
ERR1="File does not exist - try again with correct file number"
#Some description how it works
echo ""
echo "Hello!"
echo ""
echo "Script will create C, E, V records from P1 file"
echo ""
echo "Type file name without prefix & extension - example 123456023A"
echo ""
read filename
cd $P1_DIR
#It's taking H,C,E,V records from P1 file
if [ -f NSR$filname.p190 ]; then
#It's taking ...
grep ^H NSR$filename.p190 > hdr
grep ^C NSR$filename.p190 > Crec
grep ^E NSR$filename.p190 > Erec
grep ^V NSR$filename.p190 > Vrec
#it's creating E,V,C records and save as we want :)
cat hdr Erec > "NSR${filename}_Erec.p190"
cat hdr Vrec > "NSR${filename}_Vrec.p190"
cat hdr Crec > "NSR${filename}_Crec.p190"
#cd $P1_DIR
mv $P1_DIR"NSR${filename}_Erec.p190" $CEV_DIR
mv $P1_DIR"NSR${filename}_Vrec.p190" $CEV_DIR
mv $P1_DIR"NSR${filename}_Crec.p190" $CEV_DIR
echo ""
else
echo "$ERR1"
exit 1
fi