LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

Reply
 
Search this Thread
Old 07-03-2006, 03:54 AM   #1
bondoq
Member
 
Registered: Nov 2004
Posts: 77

Rep: Reputation: 13
sed and awk in shell script


i want to understand and use

sed and awk in the shell script
 
Old 07-03-2006, 04:02 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
uh huh. good for you. did you want to ask a question?
 
Old 07-03-2006, 04:09 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
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.
 
Old 07-03-2006, 04:09 AM   #4
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,514

Rep: Reputation: 90
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
 
Old 07-03-2006, 04:25 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
I'd like a Double Cheeseburger, extra large Coke and some fri... hey, can you put that in a meal?
 
Old 07-03-2006, 04:30 AM   #6
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,514

Rep: Reputation: 90
Sure, get it here: http://www.brackenstore.com/images/b...eeseburger.jpg
 
Old 07-03-2006, 05:18 AM   #7
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Oh man I'm hungry...
 
Old 07-03-2006, 06:38 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
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...
 
Old 07-03-2006, 12:45 PM   #9
320mb
Senior Member
 
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 47
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..........
 
Old 07-25-2007, 11:55 PM   #10
onlynimal
LQ Newbie
 
Registered: Apr 2006
Location: Chennai
Posts: 12

Rep: Reputation: 0
Lightbulb 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
 
Old 07-26-2007, 01:39 AM   #11
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Awk by example: http://www-128.ibm.com/developerwork...ry/l-awk1.html
 
Old 07-26-2007, 02:15 AM   #12
onlynimal
LQ Newbie
 
Registered: Apr 2006
Location: Chennai
Posts: 12

Rep: Reputation: 0
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
 
Old 07-26-2007, 07:43 AM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Maybe a bit anticlimactic, but my favorite sed and awk tutorials are at:
http://www.grymoire.com/Unix/
 
Old 07-26-2007, 07:58 AM   #14
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 50
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.
 
Old 07-27-2007, 01:52 AM   #15
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
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 ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 10:54 PM
shell script problem on sed. chooi Programming 3 02-10-2006 11:35 PM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM
Accessing Shell variable in awk script dileepkk Linux - General 1 10-07-2004 07:47 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM


All times are GMT -5. The time now is 11:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration