Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-03-2006, 03:54 AM
|
#1
|
Member
Registered: Nov 2004
Posts: 77
Rep:
|
sed and awk in shell script
i want to understand and use
sed and awk in the shell script
|
|
|
07-03-2006, 04:02 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
uh huh. good for you. did you want to ask a question?
|
|
|
07-03-2006, 04:09 AM
|
#3
|
Senior Member
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
|
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.
|
|
|
07-03-2006, 04:09 AM
|
#4
|
Senior Member
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 current
Posts: 1,649
Rep: 
|
|
|
|
07-03-2006, 04:25 AM
|
#5
|
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545
Rep:
|
I'd like a Double Cheeseburger, extra large Coke and some fri... hey, can you put that in a meal?
|
|
|
07-03-2006, 04:30 AM
|
#6
|
Senior Member
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 current
Posts: 1,649
Rep: 
|
|
|
|
07-03-2006, 05:18 AM
|
#7
|
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545
Rep:
|
Oh man I'm hungry...
|
|
|
07-03-2006, 06:38 AM
|
#8
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
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...
|
|
|
07-03-2006, 12:45 PM
|
#9
|
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577
Rep:
|
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..........
|
|
|
07-25-2007, 11:55 PM
|
#10
|
LQ Newbie
Registered: Apr 2006
Location: Chennai
Posts: 12
Rep:
|
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
|
|
|
07-26-2007, 01:39 AM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
|
|
|
07-26-2007, 02:15 AM
|
#12
|
LQ Newbie
Registered: Apr 2006
Location: Chennai
Posts: 12
Rep:
|
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
|
|
|
07-26-2007, 07:43 AM
|
#13
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Maybe a bit anticlimactic, but my favorite sed and awk tutorials are at:
http://www.grymoire.com/Unix/
|
|
|
07-26-2007, 07:58 AM
|
#14
|
Senior Member
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561
Rep:
|
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
Last edited by frenchn00b; 07-26-2007 at 08:00 AM.
|
|
|
07-27-2007, 01:52 AM
|
#15
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
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 12:34 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|