The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace a character with another character satish@123 Shell Programming and Scripting 8 05-13-2009 04:04 PM
Can I read a file character by character? murtaza Shell Programming and Scripting 4 04-27-2009 06:51 AM
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 04:18 PM
Can i read a file character by character karnan Shell Programming and Scripting 6 05-19-2008 03:22 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 10-26-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Setting FS to more than one character

Hi!

In an awk tutorial i was reading (from www.grymoire.com), it was mentioned that i can set the input field separator to more than one character using FS. However when i tried it out, it wasnt working.

File a :

abc/:/:as
as/:f/:f
AE/:/:as/:/:s


script a.sh

#!/bin/awk -f
BEGIN {
FS="/:";
}

{
print $1, $2;
}



command:

home/# as.sh<a
abc :
as :f
AE :


however, the output i shud get is
abc
as f
AE

can someone tell me what am i doing wrong here?
  #2 (permalink)  
Old 10-26-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Theat awk command worked fine for me. Try replacing awk with nawk.
  #3 (permalink)  
Old 10-26-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Quote:
Originally Posted by vino
Theat awk command worked fine for me. Try replacing awk with nawk.
Thanks! it worked. But why didnt awk work? coz the tutorial was written for Awk, not nawk. The tutorial was for Solaris n my flavor is also Solaris. It was written in 1989 tho - did that make any difference?
  #4 (permalink)  
Old 10-26-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
Solaris has a crippled version of awk - which is the default. It also has nawk which is more like new awk and supports features.

There are POSIX standards for awk which came out long after the awk version Solaris has...

see:
http://www.opengroup.org/onlinepubs/...ities/awk.html

POSIX is a set of standards developers of most flavors of UNIX try to follow.
This allows, for example, somebody here running Linux to get an example from someone else on this forum - that other person runs Solaris - and there will be a good chance it works on both boxes. Solaris doesn't play POSIX with awk, but it's there to support old code. Just use nawk and forget awk. IMO.
  #5 (permalink)  
Old 10-27-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
thanks! after a cloudy day, its a sunny one again!
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 09:31 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