Sponsored Content
Top Forums UNIX for Dummies Questions & Answers File handling in bash shell scripting Post 302495413 by reeta_shri on Thursday 10th of February 2011 06:57:24 AM
Old 02-10-2011
sample outout will be

0001256457558
001644855855960790
002494850496568568

starting 000,001 and 002 is fixed and rest data is variable and 485585 coming from the input file.

my whole code is below
#!/bin/sh
# write the output file header
function header()
{
rec_typ=000
file_var=00001
fieldid_1=BP
fieldid_2=`date +%y%m%d`
fieldid_3=XXXXXX
flag=P
echo $rec_typ $file_var $fieldid_1$fieldid_2$fieldid_3 $flag > output.txt
}
# append the BPF file with data record and extract the KID information
function transaction1()
{
rec_typ=001
bin_num=$1
account_num=$2
ref_num=
debit_rej_cde=
payment_cde=XXX
adjust_cde=
cre_deb_cde=
pay_curr_cde=
sett_ref_num=
o_sett_ref_num=
o_tran_num=
pay_amount=
card_number=
echo $rec_typ $bin_num $account_num $ref_num $debit_rej_cde $payment_cde $adjust_cde $cre_deb_cde $pay_curr_cde $sett_ref_num $o_sett_ref_num $o_tran_num $pay
_des $pay_amount $card_number >> BPF
}
#append the BPF file with this record
function transaction2()
{
echo="ABC"
}
#append the BPF file with transaction3 record
function transaction3()
{
pay_des=
}
#append the BPF file with trailer record
function trailer ()
{
rec_typ=002
deb_amount=
deb_count=
cre_amount=
cre_count=
}
#if [ -f "OCR.txt"]; then
END=no
while [ $END=no ]
do
exec a1
echo $a1
rectype=`line | cut -c1-2`;
echo "$rectype"
case "$rectype" in
10)
header
echo "inside header"
continue
;;
20)
echo "inside batch header"
continue
;;
30)
BIN=`line | cut -c13-18`;
ACCOUNT=`line | cut -c19-30`;
echo "$ACCOUNT"
transaction1 "$BIN" "$ACCOUNT"
echo "inside transaction1"
continue
;;
31)
transaction2
echo "inside transaction2"
continue
;;
32)
transaction3
echo "inside transaction3"
continue
;;
88)
echo "inside batch trailer"
continue
;;
89)
trailer
echo "inside trailer"
END=yes
exit 0
;;
*)
echo "$rectype"
echo "reeta error in the file"
exit 1 #exit script with error
;;
esac
done < "input.txt"
#read of file
#exit script OK
# fi

may be now you will get better idea what i am trying to do.
code is working file only thing BIN=`line | cut -c13-18`; extracting data from the next line of the input file i want to extarct data from current line of the input file.

thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file handling with ksh scripting

how can i write content of a variable to a file? how can i read standard output into a variable? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

2. Shell Programming and Scripting

bash shell scripting

Hi, i am new to UNIX. I have couple of basic questions. 1. Is the syntax for BASH shell programming same in the LINUX and SUN SOLARIS operating systems? 2. I have to work on BASH shell programming in SUN SOLARIS operating system. I am going through the documentation from the following... (4 Replies)
Discussion started by: azazalis
4 Replies

3. Shell Programming and Scripting

Help!! bash shell scripting..

Can any1 please help me... i'm really lost in using bash shell scripting... and i got to hand this up on monday... please anyone teach me how to do this assignment... Please use basic things because i just learn the program only... thanks ... (1 Reply)
Discussion started by: Fr0z3n999
1 Replies

4. Shell Programming and Scripting

Bash shell Scripting help

wwww wwwwwwww wwwwwwwwwwwww (0 Replies)
Discussion started by: keyvan
0 Replies

5. Shell Programming and Scripting

File handling with bash shell scripting

Hi all, Can anyone guide to get tricks for file handling in bash shell? Thanks in advance. Thanks Deepak (2 Replies)
Discussion started by: naw_deepak
2 Replies

6. Shell Programming and Scripting

Error handling in Unix shell scripting

Hello, I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log set pagesize 0 set feedback off set heading off set linesize 200... (1 Reply)
Discussion started by: rksingh003
1 Replies

7. Homework & Coursework Questions

Help with bash shell scripting

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a bash shell script that takes as an argument a name. Then your script will ask the user for two numbers.... (15 Replies)
Discussion started by: boyboy1212
15 Replies

8. Shell Programming and Scripting

Bash shell scripting doubt

Hello All, I am setting up a cron job, where i am calling a shell script to make few builds. I got struck at a point, need some expert inputs to proceed further. The script is categorized in 5 parts and in the last part while building software it asks for few questions like:- 1. Build mode... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

9. UNIX for Dummies Questions & Answers

BASH Shell Scripting: If, Then Statement

I'm having trouble trying to create a BASH shell script. I want the user to input a command "cat file_name.c" and then the shell script will delete all comments "/* */" from file_name.c else exit. So far I have this: #!/bin/bash read "cat file" // User will input command cat... (7 Replies)
Discussion started by: inkjoy00
7 Replies

10. UNIX for Dummies Questions & Answers

Learn bash shell scripting

I do not know shell scripting. But at work place, I have got an in and out shell scripting task. I just need to understand a very big script. Is there any tool in which I can place the script and it can tell me the meaning of the whole script? (3 Replies)
Discussion started by: lg123
3 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 02:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy