LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed and awk in shell script (https://www.linuxquestions.org/questions/linux-newbie-8/sed-and-awk-in-shell-script-460506/)

bondoq 07-03-2006 03:54 AM

sed and awk in shell script
 
i want to understand and use

sed and awk in the shell script

acid_kewpie 07-03-2006 04:02 AM

uh huh. good for you. did you want to ask a question?

raskin 07-03-2006 04:09 AM

Well, it's not easy to express desire to have received advice to read man sed, man awk, info sed, info awk, man 7 regex.

titopoquito 07-03-2006 04:09 AM

Bash Beginner's Guide:
http://www.tldp.org/LDP/Bash-Beginners-Guide/

Advanced Bash Scripting Guide:
http://www.tldp.org/LDP/abs/html/

Sed oneliners:
http://www.student.northpark.edu/pem...d/sed1line.txt

cs-cam 07-03-2006 04:25 AM

I'd like a Double Cheeseburger, extra large Coke and some fri... hey, can you put that in a meal?

titopoquito 07-03-2006 04:30 AM

Sure, get it here: http://www.brackenstore.com/images/b...eeseburger.jpg :D

cs-cam 07-03-2006 05:18 AM

Oh man I'm hungry...

acid_kewpie 07-03-2006 06:38 AM

ok ok guys, let's get back on track. wasn't the best start to a thread ever, but this is their thread, not yours...

320mb 07-03-2006 12:45 PM

Quote:

Originally Posted by bondoq
i want to understand and use

sed and awk in the shell script

Code:

#!/bin/bash
#random-ogg: play a random file from jukebox
mount /dev/hdb8
cd /home/music

filename=$(find -type f |
    gawk 'BEGIN{
    srand()
}
{   
    names[NR]=$0
}
      END{ i=1+int(rand()*NR)
      print names[i]
}
')
echo "$filename"
mplayer "$filename"

here is an example of awk/gawk in use......this script looks thru my ogg files and chooses one at random and plays it thru mplayer..........one can also edit it to use xine, xmms, etc and it can choose mp3 files also..........

onlynimal 07-25-2007 11:55 PM

how to extract a particular word from a string in Shell scripting
 
hye,

since i'm not able to start a new thread, i'm raising my question here.
I have a variable saying $remaining="/etc /var /sns /vol"(which is assigned at runtime)
i want to check whether '/sns' is present in that. If it is, it should be removed and the string must be like $remaining="/etc /var /vol"
Can I use awk command to do that.
Plz help.Thnx in advance

chrism01 07-26-2007 01:39 AM

Awk by example: http://www-128.ibm.com/developerwork...ry/l-awk1.html

onlynimal 07-26-2007 02:15 AM

thanks.
but i want to extract from a string. not from a file..
so i dont think that 'awk' will work for this. can u suggest some other command in shell

pixellany 07-26-2007 07:43 AM

Maybe a bit anticlimactic, but my favorite sed and awk tutorials are at:
http://www.grymoire.com/Unix/

frenchn00b 07-26-2007 07:58 AM

Quote:

Originally Posted by 320mb
Code:

#!/bin/bash
#random-ogg: play a random file from jukebox
mount /dev/hdb8
cd /home/music

filename=$(find -type f |
    gawk 'BEGIN{
    srand()
}
{   
    names[NR]=$0
}
      END{ i=1+int(rand()*NR)
      print names[i]
}
')
echo "$filename"
mplayer "$filename"

here is an example of awk/gawk in use......this script looks thru my ogg files and chooses one at random and plays it thru mplayer..........one can also edit it to use xine, xmms, etc and it can choose mp3 files also..........

That's cool to embed the awk code into the bash. Too, can you do so with perl embeded into bash ?
nice script


btw, this is a nice tuto / book / pdf:
(not in english, sorry)
http://www.bamboo.hc.edu.tw/linux/document/awk.pdf

chrism01 07-27-2007 01:52 AM

Re Perl, sure.
Normally all the Perl progs i write are self-sufficient, but there's no reason you can't call them from within a shell script.
After all, you call them from the cmd line (bash) anyway ...


All times are GMT -5. The time now is 04:53 PM.