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
thousands separator ynixon Shell Programming and Scripting 11 04-13-2008 10:43 AM
regexp to print after a field seperator ramky79 Shell Programming and Scripting 7 05-09-2007 06:31 PM
how to include field separator if there are blank fields? ReV Shell Programming and Scripting 19 07-13-2005 04:50 AM
How do I specify tab as field separator for sort? SSteve UNIX for Dummies Questions & Answers 8 04-26-2005 04:39 PM
Separator in Makefile? laila63 Shell Programming and Scripting 2 07-01-2004 10:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2006
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
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?
  #2 (permalink)  
Old 02-15-2006
bigearsbilly bigearsbilly is offline
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
  #3 (permalink)  
Old 02-15-2006
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
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?
Sponsored Links
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 05:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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