The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
regex question xiamin Shell Programming and Scripting 3 03-05-2009 02:53 AM
RegEx question has me stumped tolmark UNIX for Dummies Questions & Answers 7 08-18-2007 06:20 PM
Quick regex question retrovertigo Shell Programming and Scripting 1 07-06-2007 04:49 PM
Newbie Regex Question ciremg01 UNIX for Dummies Questions & Answers 0 11-30-2005 05:30 PM
regex question rocketkids UNIX for Dummies Questions & Answers 6 02-12-2004 05:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2007
arushunter arushunter is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
regex question

I have a simple file test.out that contains data in the form of

key1=A|shift1
key2=B|shift2
key3=C|shift3

and so on.

I need to get it to print

A
B
C

I can do it using lookbehind assertion such as this
( ?<==)([a-zA-Z])

yet I was wondering if there is another way of mutching single character following the '=' ?. I am fairly new to regex and so far I could not find good way of matching a part of a string after or before certain characters or set of characters other that using assertions.
Any examples would be helpful.
thank you in advance
  #2 (permalink)  
Old 01-04-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed "s/[^=]*=\(.\).*/\1/" file
  #3 (permalink)  
Old 01-04-2007
arushunter arushunter is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
thank you it worked.
  #4 (permalink)  
Old 01-04-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
awk one

Code:
awk -F'[=|]' '{print $2}' testfile
  #5 (permalink)  
Old 01-04-2007
arushunter arushunter is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 31
Being on the same topic I have another question.
If I have files that contains following data

key1^A|shift1|376
key2^B|shift
key3^C|shift23|2|5

and so on

how would I change first instance of the '|' to '^' ?

to have something like this

key1^A^shift1|376
key2^B^shift
key3^c^shift23|2|5

I tried
sed 's/.+\d\^[a-zA-Z]\|.*/s/.+\d\^[a-zA-Z]\^.*/'

but that did not work
thank you in advance
  #6 (permalink)  
Old 01-04-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
check this

actually its simple sed substitution -
Code:
sed 's/|/^/' testfile
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:45 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