awk,nawk,sed, delimiter |~|


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk,nawk,sed, delimiter |~|
# 1  
Old 02-18-2008
awk,nawk,sed, delimiter |~|

Code:
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.

Code:
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  
Old 02-18-2008
And if you try:

Code:
nawk -F'|~|' '{print$2 $3}' filename

?
# 3  
Old 02-18-2008
Code:
nawk -F'|~|' '{print$2 $3}' filename
nawk: illegal primary in regular expression |~| at ~|
 input record number 1, file filename
 source line number 1

# 4  
Old 02-18-2008
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  
Old 02-18-2008
Thanks , after using awk, gawk in the following directory. it does work.

Code:
/usr/xpg4/bin/awk

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

this is what I wanted. works for me.

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

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

Code:
which awk
/usr/bin/awk
awk    -F'|~|' '{print$2}' filename
~

# 6  
Old 02-18-2008
Why not use

Code:
awk -F\| '{print $3}'

# 7  
Old 02-18-2008
Code:
awk -F\| '{print $3}'

This only gives me the the 3rd filed

if I would like to get $4 $5 and so on.

Code:
awk -F\| '{print $3 $4 $5}'

Then it doesnt work
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

2. Shell Programming and Scripting

Need help parsing data with sed and/or nawk

Good day all. I have the following entries of data in a file in a column, however, I need this data written on a single line with several parameters in a different order. Current format: Treatment ,parmeter1=value ,parmeter2=value ,parmeter3=value ,parmeter4=value... (7 Replies)
Discussion started by: BRH
7 Replies

3. Shell Programming and Scripting

nawk won't accept comma as delimiter

I have a text file delimited by commas, with three fields (no " marks). I want to use awk to create a fourth field which is equal to the line number + field 1 + .txt I've searched this forum and found the following nawk -v OFS=';' '{print $0, FNR}' myFile Which I've amended to change the... (2 Replies)
Discussion started by: b.hamilton
2 Replies

4. Shell Programming and Scripting

sed delimiter

HI all,, I hve defined something like set data = /data/2012/text while using sed 's/$data//g' I am getting error as:I understand this is due to / slash,but is there any way out of it.... sed: -e expression #1, char 12: unknown option to `s' Thakns in adv. (6 Replies)
Discussion started by: Indra2011
6 Replies

5. Shell Programming and Scripting

Sed/Nawk help

Hi all, I have the following piece of code which reformats a file but the part that isn't working converts a date from dd mmm ccyy format to 2 fields containing dd/mm/ccyy,ccyy-mm-dd hh:mm:ss.000000 This is for a DB2 load file. The problem I have is that the input dd values (the dd variable... (2 Replies)
Discussion started by: dazedandconfuse
2 Replies

6. Shell Programming and Scripting

using a another delimiter with sed?

Hi there, After lots of reading I figured out how to use sed to parse my file. This file is called services.txt: 00a1:ffff0000:0018:01f4:1:477 BravaNL 00a2:ffff0000:0018:01f4:1:471 MAX 00a3:ffff0000:000b:01f4:1:390 HaberTürk... (5 Replies)
Discussion started by: MastaG
5 Replies

7. Shell Programming and Scripting

Implement in one line sed or awk having no delimiter and file size is huge

I have file which contains around 5000 lines. The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters. I want to delete the lines a> if it starts with 1 and if 576th postion is a digit i,e 0-9 or b> if it starts with 0 or 9(i,e header and footer) ... (4 Replies)
Discussion started by: millan
4 Replies

8. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

9. Shell Programming and Scripting

Need help in sed or nawk replace RE

Dear Friends, I am trying to replace the following pattern , But I cant understand how to express the RE in this case . Please help me with a sed command to replace . (Address = 918h : Initial = 0000h : RD /WR (Address = 91Ah : Initial =... (2 Replies)
Discussion started by: user_prady
2 Replies
Login or Register to Ask a Question