The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
thousands separator ynixon Shell Programming and Scripting 11 04-13-2008 07:43 AM
regexp to print after a field seperator ramky79 Shell Programming and Scripting 7 05-09-2007 03:31 PM
how to include field separator if there are blank fields? ReV Shell Programming and Scripting 19 07-13-2005 01:50 AM
How do I specify tab as field separator for sort? SSteve UNIX for Dummies Questions & Answers 8 04-26-2005 01:39 PM
Separator in Makefile? laila63 Shell Programming and Scripting 2 07-01-2004 07:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-15-2006
Registered User
 

Join Date: Sep 2005
Location: Chennai
Posts: 80
field separator as regexp

I have some version of AWK that does not support regular expression field separators ( neither do I have nawk or gawk). How do I go about reading a line with the field separator as either the string "=#" or "+=".

My data looks like this:

abhishek=#nnnnn+#1234+#87


One option is to use tr and change "=" to "+" (I am sure "=" doesnt appear anywhere else), but since the file is rather large,and there are a lot of operations I was planning to do on the fields,while I was reading the file line by line, I would refrain from using it.

Any suggestions please?
Reply With Quote
Forum Sponsor
  #2  
Old 02-15-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
use perl.

no problems splitting that.
for example:
Code:
$ cat 1
abhishek=#nnnnn+#1234+#87

$ cat 1| perl -naF'/(\=#|\+#)/'  -e '$"=" "; print "@F"'
abhishek =# nnnnn +# 1234 +# 87
or
Code:
$ cat 1| perl -naF'/\=#|\+#/'  -e '$"=" "; print "@F"'
abhishek nnnnn 1234 87
Reply With Quote
  #3  
Old 02-15-2006
Registered User
 

Join Date: Sep 2005
Location: Chennai
Posts: 80
Thanks a lot! But can you explain the syntax? I am aware of some basic PERL (but hardly oneliners!), and can make out that you're splitting $_ on the patterns "+#" or "=#" and assigning it it to the array F. But I dont understand much of anything else in the statement.Could you tell me where could I enter further statements to process the fields in the loop body (say, an if statement to test something on the second array parameter)?

Also, if possible, can you suggest some on-line PERL one-liner references?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0