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
# 1  
Old 01-09-2010
Need a better understanding of shell scripts

Need a better understanding of shell scripts

Last edited by sureshkumar4737; 01-12-2010 at 05:59 AM..
# 2  
Old 01-09-2010
if sed or awk work, why use another way? is this homework?
# 3  
Old 01-09-2010
its not a homework. I am learning shell scripting and i am trying to understand the different possibilities to solve a particular problem..

sed looks like a single line command, with which i can acheive the above said result.
but i am trying to get a multi line script to under shell better...
# 4  
Old 01-09-2010
Something working with your example (file1 contains the atom data)
Code:
#!/bin/bash
for TXT in $(grep -o 'ftp://.*' file1)
do	TXT=${TXT%/\"/>*};	echo "$TXT"
done

# 5  
Old 01-09-2010
Without using sed or awk, cut might be your next option. Try this:

Code:
grep "ftp://" logfile | cut -d'"' -f4

This will first look for any line containing "ftp://", then extract the 4th field delimited by ". This only works if all the ftp addresses occur in this form. Hope it helps.
# 6  
Old 01-09-2010
Thanks frans & 2pugs...
Your reply was really helpful...

Last edited by sureshkumar4737; 01-12-2010 at 06:00 AM..
# 7  
Old 01-09-2010
In that case, this might work for you. Basically it will look line by line in your log file and look for atom start/end entries. It uses a "switch" variable called "recording" that turns ON and OFF based on if it found an entry. Let me know if any of it is unclear. Hope it helps.

Code:
# Initialize recording to "OFF"
recording=OFF
while read line
do
  if [ "${line}" = "^<atom:entry>" ]
  then
    # Atom entry start, switch recording to "ON"
    recording=ON
  fi

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


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

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