Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

awk function problem

Posted on 2005-04-29
2
Medium Priority
?
536 Views
Last Modified: 2013-12-26
I have a mbox parser from an old script that I have turned into a bash function,
but, as normal for me, there is what I believe to be a typo somewhere in it that I cannot find.
Or, I am missing a basic point in dealing with functions.

The error I get is:
"awk: cmd. line:22: (FILENAME=- FNR=1) fatal: expression for `>' redirection has null string value"
NOTE: because this function is within another script line 22 is print>fname; (I THINK) when run alone.

anyway command test is `mailsplit <mbox`


### BEGIN (#!/bin/bash gnu version)
mailsplit()
{
awk 'BEGIN {
blankline = 1;
message = -1;
}
(/^From / && blankline) {
print "case 1"
blankline = 0;
if (message >= 0)
{
close(fname);
}
message++;
fname = sprintf("%04d", message);
print "(" fname ")" $0
}
{
if (NF == 0)
blankline = 1
else
blankline = 0;

print>fname;
}
'
}
### end
0
Comment
Question by:ALEx604
2 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 500 total points
ID: 13900209
The problem is that "fname" has not been defined the first time "print>fname" line is executed; This would happen if the first line of the awk input file doesn't start with "From"

You can avoid a problem with a malformed input file by e.g. defining
fname="junk"
in your BEGIN statement to catch any garbage lines

Also, I'm not clear how you're calling the function; Presumably there's a line  "mailsplit mbox" further down in the script, so that awk "knows" what its input file is?
0
 
LVL 2

Author Comment

by:ALEx604
ID: 13901396

Actually it turns out this function works fine.

The error I was getting was a result of something else in the script, totally my bad.

I thought I had deleted this question. Oh well.....

well, since it was my fault that this is still here, you get the points.

;)

ALEx604
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question