Need a better understanding of shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a better understanding of shell scripts
# 8  
Old 01-09-2010
Thanks for your immediate response..

i tried your above code.. but its not working..

its not throwing any error. But outfile is not created. Hope u can help me on this..
# 9  
Old 01-09-2010
Can you post the error you're getting? It might be a syntax error I missed.
# 10  
Old 01-09-2010
Thanks for your reply..

I tried the above code.. but outfile is not created.. i cant see any error message too..
# 11  
Old 01-09-2010
Sorry. I misread and thought there was an error. I added a few lines just for debugging. This should output to the script what it's find. Let me know if this works.
Code:
rm outfile  # Start with a new outfile each time
# Initialize recording to "OFF"
recording=OFF
while read line
do
  if [ "${line}" = "^<atom:entry>" ]
  then
    # Atom entry start, switch recording to "ON"
    recording=ON
    echo "DEBUG: Switching recording to ON" ; sleep 2
  fi

  if [ "${recording}" = "ON" ]
  then
    # If we are recording, record entry to outfile
    echo ${line} >> outfile
  fi
  echo "DEBUG: \$recording=$recording \$line=$line"


  if [ "${line}" = "^</atom:entry>" ]
  then
    # End of atom entry, switch recording to "OFF"
    recording=OFF
    echo "DEBUG: Switching recording to OFF" ; sleep 2
  fi
done < inputfile

if [ -f outfile ]
then
  echo "DEBUG: outfile created"
  ls -l outfile
else
  echo "DEBUG: outfile NOT created"
fi

# 12  
Old 01-09-2010
Thanks for your support..

its debugging and showing the message as

....
......
.....
DEBUG: $recording=OFF $line=<mitt:group>100</mitt:group>
DEBUG: $recording=OFF $line=</atom:entry>
DEBUG: $recording=OFF $line=</atom:feed>
DEBUG: outfile NOT created
# 13  
Old 01-09-2010
It looks like it's not finding the start and end atom entries so it is never switching it ON. My first guess is maybe it's the "^" I added to tell it's at the beginning of the line. Let's try removing it for both start and end. So instead of

Code:
  if [ "${line}" = "^<atom:entry>" ]
.
.
.
  if [ "${line}" = "^</atom:entry>" ]

You would have:
Code:
  if [ "${line}" = "<atom:entry>" ]
.
.
.
  if [ "${line}" = "</atom:entry>" ]

# 14  
Old 01-09-2010
Thanks a lot.. that really works...

i am trying to understand each and every line... it will be helpful in my future scripts.. thanku..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Understanding the difference between individual BASH login scripts

Hello... and thanks in advance for reading this or offering me any assistance I'm trying to understand specific differences between the various login scripts... I understand the differences between interactive vs non-interactive and login vs non-login shells... and that's not where my question... (4 Replies)
Discussion started by: bodisha
4 Replies

2. Shell Programming and Scripting

Trouble understanding shell scripting (mostly wsname)

Am still learning Scripting and I come across a build command that I don't really understand if /local/bin/wsname 2>/dev/null; then base="`/local/bin/wsname`" export base fi if ; then /local/bin/wsname exit 1 fi WSNAME="$base"/ can some one in light me to what... (1 Reply)
Discussion started by: Wpgn
1 Replies

3. Shell Programming and Scripting

Understanding Shell Scripting

Hi Gurus, Im new to Shell scripting. I have a shell script which basically sends an email when called thorugh my ETL tool. Wanted to understand the its functionality in detail. Would be great it any one can explain what exactly the commands to #!/bin/sh # Dummy UUCP rmail command for... (1 Reply)
Discussion started by: r_t_1601
1 Replies

4. IP Networking

Help understanding iproute2 and tc scripts

Hi all, I am new to linux routing and would like to keep a possible running dialog about some scripts I have been studying and what the different parts of them mean. We are using Openwrt backfire along with openvpn and Swyx as VoIP. My goal is to eventually implement some QoS using dsmark, but... (1 Reply)
Discussion started by: shodg001
1 Replies

5. Shell Programming and Scripting

Problem with the shell script for understanding

Can Anybody please tell me the meaning of the script: #!/bin/sh str=$@ echo $str | sed 's/.*\\//' exit 0 (6 Replies)
Discussion started by: nixhead
6 Replies

6. Shell Programming and Scripting

shell script behavior is strange or I'm not understanding

Hi I have wrote the small script, where $SRC=$HOME the input file is simple text file having directories in my $SRC on pre line desktop download myfiles games #!/bin/bash FILENAME=$1 ERROR_LOG="$SRC/err.$$.log" while read line do echo "########## strat Gmake $line... (6 Replies)
Discussion started by: the.reverser
6 Replies

7. Shell Programming and Scripting

Understanding a Shell Script

Hi Guys, I am absolutely a newbie to Solaris 8.0. Following is a piece of code in a script (/bin/sh). Can anybody help me in deciphering this ? Please see my questions after the script code - _____________________________________________________ /bin/rm -f mycron crontab -l | grep -v... (5 Replies)
Discussion started by: angshuman_ag
5 Replies

8. Shell Programming and Scripting

Understanding a Simple Shell Script

#! /usr/bin/ksh old=$1 new=$2 for file in *.$old ; do mv $file ${file%$old}$new done exit 0 This script i got from the forum. script changes the extension of the files say example a.txt to a.doc b.txt to b.doc c.txt to c.doc d.txt to d.doc this scipt works fine but i am not... (2 Replies)
Discussion started by: vijays3
2 Replies

9. Shell Programming and Scripting

Need help on understanding the Shell and AWK scripts

Hello Friends, I am new to the scripting & have to analyze bunch of regular production scripts. It has .ksh which calls on the .awk script having many functions I need to understand and debug the scripts ASAP Can anybody please let me know as how can I debug, I want to see the flow of code... (3 Replies)
Discussion started by: amberj123
3 Replies

10. UNIX for Dummies Questions & Answers

Understanding System Vish startup scripts

I'm trying to get a clear picture of how startup scripts are executed during bootup. When run-level N is entered, the scripts in /rcN.d are executed. I understand that the S* scripts are executed in numerical order during bootup. What I don't understand is if the K* scripts are executed... (0 Replies)
Discussion started by: darkmatter14B
0 Replies
Login or Register to Ask a Question