![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 11:43 AM |
| regexp to print after a field seperator | ramky79 | Shell Programming and Scripting | 7 | 05-09-2007 07:31 PM |
| how to include field separator if there are blank fields? | ReV | Shell Programming and Scripting | 19 | 07-13-2005 05:50 AM |
| How do I specify tab as field separator for sort? | SSteve | UNIX for Dummies Questions & Answers | 8 | 04-26-2005 05:39 PM |
| Separator in Makefile? | laila63 | Shell Programming and Scripting | 2 | 07-01-2004 11:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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 |
|
||||
|
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? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|