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
Help me for AWK URGENT readycpbala Shell Programming and Scripting 2 02-22-2007 01:03 PM
URGENT,URGENT- Need help tape drive installation sriny UNIX for Advanced & Expert Users 3 11-16-2006 03:43 PM
URGENT---URGENT--No OK PROMPt after RSC CONFIG sriny SUN Solaris 7 10-29-2006 11:06 AM
Urgent !! desiondarun UNIX for Dummies Questions & Answers 1 08-08-2006 09:49 AM
urgent 2 hamoudzz UNIX for Dummies Questions & Answers 1 03-03-2004 09:09 PM

Closed Thread
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 10-25-2007
SanjayLinux SanjayLinux is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 58
Unhappy Need Help Urgent

Hi Guys,
Need one quick help.
I have one file test.sh
#cat test.sh
<Abc>200712241314</Abc>

I need the output value in between <Abc> </Abc> mean to say "200712241314"

I am using cut command for that. But my problem is that test.sh file not same format. Some time it will have some whitespace from start.

Could you help me.

I want the ouput value in between <Abc> </Abc> in anywhere that file.

It is Urgent !!
Thanks
Sanjay
  #2 (permalink)  
Old 10-25-2007
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,641
man sed - urgently!!

I guess that you do not have multiple <Abc>..</Abc>-combinations on one line so that following line would be impossible:


Code:
 blabla  <Abc> value1 </Abc> blabla <Abc>    value2   </Abc> blabla

If this *is* the case you should start reading the sed-manpage even more urgently, as it is going to be a little more elaborate than the simple case replace "<spc>" "<tab>" by literal blanks and tabs:


Code:
sed 's/^.*<Abc> *\([^<spc><tab>][^<spc><tab>]*\) *<\/Abc>.*$/\1/' test.sh

This removes the whitespace too.

bakunin
  #3 (permalink)  
Old 10-25-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
using Perl:
Code:
#!/usr/bin/perl
# extract_num.pl
while (<>) {
    print $1 if (m#^\s*<Abc>(\d+)</Abc>#);
}

Then run this script as:
Code:
perl extract_num.pl test.sh

  #4 (permalink)  
Old 10-25-2007
bishweshwar bishweshwar is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 56
Quote:
Originally Posted by bakunin View Post
man sed - urgently!!

I guess that you do not have multiple <Abc>..</Abc>-combinations on one line so that following line would be impossible:


Code:
 blabla  <Abc> value1 </Abc> blabla <Abc>    value2   </Abc> blabla

If this *is* the case you should start reading the sed-manpage even more urgently, as it is going to be a little more elaborate than the simple case replace "<spc>" "<tab>" by literal blanks and tabs:


Code:
sed 's/^.*<Abc> *\([^<spc><tab>][^<spc><tab>]*\) *<\/Abc>.*$/\1/' test.sh

This removes the whitespace too.

bakunin
Can you explain how this part works.......
([^<spc><tab>][^<spc><tab>]*\) & ".*$/\1" .

Thanks
Bishweshwar
  #5 (permalink)  
Old 10-29-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
Try This Out!!!!!!!!!!!!!!!!!!!!!!!!!


sed 's/\(<Abc>\)\(.*\)\(<\/Abc>\)/\2/' filename

Regards,
Anand
Closed Thread

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 08:12 PM.


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