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 > Special Forums > UNIX Desktop for Dummies Questions & Answers
.
google unix.com



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else hariza Shell Programming and Scripting 4 09-18-2008 02:56 AM
grep and fetching lines after grep arghya_owen Shell Programming and Scripting 2 07-16-2008 07:25 AM
Grep or Sed jazz8146 UNIX for Dummies Questions & Answers 5 11-13-2007 05:43 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM

Reply
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 Rating: Thread Rating: 1 votes, 2.00 average. Display Modes
  #1 (permalink)  
Old 05-25-2009
donisback donisback is offline
Registered User
  
 

Join Date: May 2009
Posts: 9
Grep

Hi,
I have a file as:
Code:
IIN*00*00*ZZ*NDC *ZZ*11847*090520*0200*U*00401*000000001*0*P*>~GS*HP*NDC STD REMIT*1184722779*20090520*0200*63*X*004010X091A1~ST*835*10001~BPR*I*252480.19*C*CHK************20090515~TRN*1*0010855862*1952931460*12427008150981~DTM*405*20090514~N1*PR*CALIFORNIA*XV*H00~N3*ireland~
I want to extract 'CALIFORNIA' from the above one line file. The file will contain 'N1*PR*------' . I want to extract the string after N1*PR*.

Appreciate your help.

Regards,
Anil
  #2 (permalink)  
Old 05-25-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,837
If it's a fixed-field record with '*' as the separator, you could use
Code:
awk -F'*' '{print $49}' file
Otherwise, if you only want the part after 'N1*PR*', this Perl snippet might help:
Code:
perl -ne 'print $1,"\n" if /N1\*PR\*(.*?)\*/;' file
  #3 (permalink)  
Old 05-25-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
if you have Python
Code:
#!/usr/bin/env python
for line in open("file"):
    if "N1*PR*" in line:
        ind=line.index("N1*PR*")
        print line[ind+6:].split("*")[0]
output
Code:
# ./test.py
CALIFORNIA
  #4 (permalink)  
Old 05-25-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

VIDYA
  #5 (permalink)  
Old 05-26-2009
donisback donisback is offline
Registered User
  
 

Join Date: May 2009
Posts: 9
Thanks. Perl one-liner worked.
Sponsored Links
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 06:16 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