The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Replacement for sed dbsurf Shell Programming and Scripting 0 01-25-2008 06:47 PM
KSH - Character Replacement mixxamike Shell Programming and Scripting 2 09-24-2007 04:43 PM
Regarding Replacement rajx UNIX for Dummies Questions & Answers 2 05-22-2007 10:19 AM
Replacement using sed handak9 UNIX for Dummies Questions & Answers 5 07-13-2004 12:28 PM
cpu replacement. help IMPTRUE UNIX for Dummies Questions & Answers 3 07-25-2003 09:40 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2009
priyam priyam is offline
Registered User
  
 

Join Date: Jul 2008
Location: India
Posts: 24
Awk replacement

Hi all,

I need help in replacing awk with sed for the below.

1 )
Code:
 cat list | awk -F" |," '/MATH/ {sub(/[[:alpha:]]*/,"",$3); print $3}'

Eg: file : list
Sno Subno Name
1 SUB1 ENG
2 SUB2 MATH
2)
Eg:result
Total No of Students: 2

Sno ID Sub
------------------
1 120 ENG
2 2 ENG
3 10 MATH

Here I need no of students

Code:
cat result | awk '/Total/ {print $5}'

the o/p would be : 2
other case , I need the IDs alone

Code:
cat result| awk '{print $2}' | grep '[[:digit:]]' | tr '\n' ' '

The o/p would be : 120 2 10


For the above what can be the possible sed replacements ?

Thanks,
Priya.
  #2 (permalink)  
Old 09-28-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,380

Why do you want to use sed? Is this homework?

Awk is the right tool for the job. (But get rid of those UUOCs.)
  #3 (permalink)  
Old 09-29-2009
priyam priyam is offline
Registered User
  
 

Join Date: Jul 2008
Location: India
Posts: 24
Not homework

No this is not homework. Unfortunately one of the embedded system I work on doesnt support awk.Hence the requirement.


Thanks,
Priya.
  #4 (permalink)  
Old 09-29-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
one way..

Code:
-bash-3.2$ cat file
Total No of Students: 2
-bash-3.2$ cut -d" " -f5 file
2
-bash-3.2$

-bash-3.2$ cat file2
Sno ID Sub
------------------
1 120 ENG
2 2 ENG
3 10 MATH
-bash-3.2$ grep [[:digit:]] file2 | cut -d" " -f2
120
2
10
-bash-3.2$

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0