I want a small change in my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I want a small change in my script
# 1  
Old 06-07-2008
Question I want a small change in my script

Hi All,

I have a script like this which read a file and take data with file seperator ,
and it is working fine for only one line.If i am giving two line of data in this file it is taking the second line only.Can anyone help me to solve the problem.My aim is to read the file each line by line.

The file entry is something like

10.99.7.110,KBL18031,/dir1,/dir2
10.99.6.154,KBL02012,/dir1/dir2

script is like this ....

while read inputline
do
ATMIP="$(echo $inputline |cut -d, -f1)"
ATMNAME="$(echo $inputline |cut -d, -f2)"
ATMDIR1="$(echo $inputline |cut -d, -f3)"
ATMDIR2="$(echo $inputline |cut -d, -f4)"

done < testdetails.conf
# 2  
Old 06-08-2008
Definitely the 2nd line entries(or last line entries) of each variable (ATMIP,ATMNAME,ATMDIR1,ATMDIR2) will be present as values in the respective variables as per your code.

Do you want to print all the values for each of the variables you are extracting using cut ? If you could provide your expected o/p, would be a great help for all to answer.

//Jadu
# 3  
Old 06-08-2008
Quote:
Originally Posted by Renjesh
Code:
while read inputline
do
        ATMIP="$(echo $inputline |cut -d, -f1)"
        ATMNAME="$(echo $inputline |cut -d, -f2)"
        ATMDIR1="$(echo $inputline |cut -d, -f3)"
        ATMDIR2="$(echo $inputline |cut -d, -f4)"

done < testdetails.conf
... #do something

If you process after the loop, that's normal to be only the last line. Try to process in loop.
Code:
while read inputline
do
        ATMIP="$(echo $inputline |cut -d, -f1)"
        ATMNAME="$(echo $inputline |cut -d, -f2)"
        ATMDIR1="$(echo $inputline |cut -d, -f3)"
        ATMDIR2="$(echo $inputline |cut -d, -f4)"
        ... #do something 
done < testdetails.conf

# 4  
Old 06-08-2008
Power

My file contains 131 entries(ATMIP,ATMNAME,/DIR./DIR ) and i want all the values instead of just last value

I am using the values for FTPing and fetching some files from the ATM.

it is something like this.......

ftp -n -v -i >> $ERRFILE 2>&1 << cmd
open $ATMIP
cd $ATMDIR1
get $FILENAME_A
cd ..
cd $ATMDIR2
cd $DATEDIR
mget $FILENAME_B
bye
cmd
# 5  
Old 06-08-2008
Quote:
Originally Posted by jaduks
Definitely the 2nd line entries(or last line entries) of each variable (ATMIP,ATMNAME,ATMDIR1,ATMDIR2) will be present as values in the respective variables as per your code.

Do you want to print all the values for each of the variables you are extracting using cut ? If you could provide your expected o/p, would be a great help for all to answer.

//Jadu
yes I want all the values............
# 6  
Old 06-09-2008
As "danmero" stated above, you should do your print(or any) operation inside the while loop(not outside).

A different look of the same:

Code:
$ awk 'BEGIN{FS=","}{print "ATMIP="$1"\nATMNAME="$2"\nATMDIR1="$3"\nATMDIR2="$4}' testdetails.conf

or

$ awk 'BEGIN{FS=",";OFS="\n"}{print "ATMIP="$1,"ATMNAME="$2,"ATMDIR1="$3,"ATMDIR2="$4}' testdetails.conf


//Jadu

Last edited by jaduks; 06-09-2008 at 02:24 AM.. Reason: Added one more solution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Small help related to date change

Hi, I am using this code in order to automate a commands in DB: begin for i in 0..23 loop dbms_output.put_line ( 'ALTER TABLE CRESTELMEDIATIONPRD501.TBLMEDIATIONCDR ADD PARTITION'||' ... (3 Replies)
Discussion started by: hitesh1907
3 Replies

2. UNIX for Dummies Questions & Answers

need help with small script

Hi I have the below file Name=abc Yr=2011 Mon=05 My script should be in such a way that whenever I run it then Month should increment by 1 and if the month is 12 then when I run the script then year should incremented by 1 and month Should become 01(I.e jan) Thanks for the help in... (6 Replies)
Discussion started by: kishu
6 Replies

3. Shell Programming and Scripting

small script correction

input cz1 87942437 87952030 M_001144992 0 + 87942537 87949664 0 3 710,114,2506, 0,2725,7087, script awk '{ n11 = split($11, t11, ",") n12 = split($12, t12, ",") for (i = 0; ++i < n11;) { s12 = $2 + t12 print $4"_xon"i, "\t",$4"_xon"i,"\t", $1,... (1 Reply)
Discussion started by: quincyjones
1 Replies

4. AIX

Need help in a small script

Hello all, could somebody help..? I have following 6 files (with white spaces in their names) This is file This is file1 This is file2 This is file3 This is file4 This is file5 This is file6 I tried to run the below script, and it did not give me desired ouput.. $ for i in `ls -1` >... (7 Replies)
Discussion started by: gsabarinath
7 Replies

5. Shell Programming and Scripting

need a small script

Hello all, i have a batmail process running on my machine(java process). i just need a script we should detect whether the batchnail is running or not.If not it should restart it. Can anyone assist me on this? (1 Reply)
Discussion started by: Rayzone
1 Replies

6. Shell Programming and Scripting

small script help

#!/bin/ksh for i in *.log* do ls $i|sed 's/\.log$//g' | while read file do echo "file $file is Running" >> lls.txt echo "***************">> lls.txt done done ------------------------------------------------------------------ the output is : file AdapterCCProvisioningInterface... (9 Replies)
Discussion started by: ali560045
9 Replies

7. Shell Programming and Scripting

small script

Hi, I am new to unix shell scripting. I just want a little script to check the no. of processes are equal to 8, then echo a successful message otherwise echo a unsuccessful message. Please help. Thanks. (3 Replies)
Discussion started by: everurs789
3 Replies

8. Shell Programming and Scripting

change small letters to capital

hi guys, I know this might be very simple for u but not for me. I simply want to print the active users, changeing the first letter in their names to capital. i guess sed it's useful but don't know how to find the correspondign capital letter and don't know how to change just the first... (16 Replies)
Discussion started by: atticus
16 Replies

9. Shell Programming and Scripting

small script help

here is a small script: if ; then echo please enter an argument fi if [ "$1" = "tom"; then a=$1 echo $a fi here is my question. if the script name is j.sh and I run it : j.sh from shell prompt: without a parameter: it prints please enter an argument but if I go with . j.sh (current... (1 Reply)
Discussion started by: rkl1
1 Replies

10. Shell Programming and Scripting

Need help in a small script

Hi all, I have a file of the following format - EXPRPT:SCN:1.1706E+10:SEQ_START:121652:SEQ_END:121664:0 ( This file name is variable and changes daily) Now in the same directory I have another set of files of the format - EXPRPT.log.0001.0000121669 Now what I am trying to do is to ... (2 Replies)
Discussion started by: super_duper_guy
2 Replies
Login or Register to Ask a Question