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
how to access values of awk/nawk variables outside the awk/nawk block? saniya Shell Programming and Scripting 5 05-13-2008 07:37 AM
from - to delimiter bighippo Shell Programming and Scripting 6 03-13-2008 02:47 AM
Cut date using y hat as delimiter tekster757 UNIX for Advanced & Expert Users 1 07-31-2007 02:14 PM
\r as delimiter in cut shweta_d Shell Programming and Scripting 5 06-07-2007 09:18 AM
Replacement of Delimiter panknil Shell Programming and Scripting 3 05-14-2007 07:35 AM

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 02-18-2008
knijjar knijjar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 27
awk,nawk,sed, delimiter |~|

RECORD=NEW|~|VENDORN=LUCENT|~|VENDORM=CBX500_REAR|~|NETWORK=ATM|~|SUBNETWORK=N/A|~|SITE=CIL|~|REGION=KN|~|COUNTRY=PS|~|SWITCH=SWITCH1|~|E
THERNET=N/A|~|LOOPBACK=N/A|~|SHELF=N/A|~|SLOT=14|~|SUBSLOT=N/A|~|STSCHAN=N/A|~|PORT=S14|~|DS1SLOT=N/A|~|LINE=N/A|~|LPORTID=N/A|~|CARDDESC=N/A|~|CARDTYPE=BAC2RT0
E|~|ENCAPSULATION=ATM|~|BUNDLEID=N/A|~|PORTUSE=N/A|~|STATUS=T|~|MANAGED=YES|~|BILLINGID=N/A|~|CKTID=5HCSILHR02W|~|CKTIP=N/A|~|PORTSERVICE=B3ZS|~
|SPEED=0|~|CHNLS=N/A|~|NX_KEY=3|

I have the following record in a file which is delimited by |~| , I would like to print only the second (VENDORN=LUCENT) and third field (VENDORM=CBX500_REAR) in this record.


nawk '{FS="|~|"; print$2 $3}' filename

nawk: illegal primary in regular expression |~| at ~|
input record number 1, file filename
source line number 1


Looks like because this delimiter has a ~ sign in between it doesnt work.

How do I make |~| as the delimiter. anyhelp is appreciated folks.

The OS I am on is SunOS 5.10
  #2 (permalink)  
Old 02-18-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
And if you try:

Code:
nawk -F'|~|' '{print$2 $3}' filename
?
  #3 (permalink)  
Old 02-18-2008
knijjar knijjar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 27
nawk -F'|~|' '{print$2 $3}' filename
nawk: illegal primary in regular expression |~| at ~|
input record number 1, file filename
source line number 1
  #4 (permalink)  
Old 02-18-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,923
Both awk and gawk work for me

Code:
$ awk -F'|~|' '{print$2 $3}' file
|VENDORN=LUCENT||VENDORM=CBX500_REAR|
$ gawk -F'|~|' '{print$2 $3}' file
|VENDORN=LUCENT||VENDORM=CBX500_REAR|
  #5 (permalink)  
Old 02-18-2008
knijjar knijjar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 27
Thanks , after using awk, gawk in the following directory. it does work.

/usr/xpg4/bin/awk

/usr/xpg4/bin/awk -F'|~|' '{print$2}' filename
VENDORN=LUCENT

this is what I wanted. works for me.


/usr/local/bin/gawk -F'|~|' '{print$2}' filename
|VENDORN=LUCENT|

gawk put "|" pipe symbol in the output which I dont want.

which awk
/usr/bin/awk
awk -F'|~|' '{print$2}' filename
~
  #6 (permalink)  
Old 02-18-2008
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Why not use

awk -F\| '{print $3}'
Closed Thread

Bookmarks

Tags
solaris

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 05:32 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