On Fri, Apr 18, 2036 at 12:28:37AM -0500, Robert Haehnel wrote:
> Yes, you are right, awk is the right tool for the job, and I have been fooling
> around with it today. I'm about 95% there, but I have one quirky result. I was
> wondering if anyone might be able to help clear up this AWKward problem.
> 
> I essentially did what you suggest Greg only I created a seperate awk script
> file, so at the command line I have
> 
> awk -f shift.awk infile > outfile
> 
> the contents of shift.awk is essentially identical to your command line.
                                ^ I think this is the key piece.

> 
> The script works beautifully except for one thing. If I let the output go to
> the screen (stdout) or to the outfile I find each line of the input file is
> echoed to the output file, and then the printed line form the awk script
> follows. So when the first field is not -1 or 0 the output is two identical
> line (one right after the other). If the first field is -1 or 0 the output is
> the line straight from the input file followed by the properly shifted line
> (created by awk). 
> 
> What gives?
        dunno.
> I've done this kind of redirection before 
> (e.g. sed -e 's/XX/YY/g' < infile > outfile)
> and it works fine so I'm not sure what is happening. Is there a defualt
> echoing in awk that I need to turn off some how?

        sometimes... It depends on your script.

        If you have a conditional outside of any braces({), if it evaluates
        to true on a line, awk will print it.

        for instance:
         awk '1' < file
         acts just like cat.

         maybe this is related to your problem.

        Could I see your script? I suspect that there's something slightly
        wrong, but guessing what it is is too hard to do without seeing
        it.

        also. I thought about it a little more, and this works with sed.

export TAB=`echo -n -e "\t"`; sed "/^0\|^-1/s/\(.*\)\([^$TAB]*[^$TAB]\)/\2$TAB\1/g"    
    ^               ^
           |---back tics---|


certainly works with bash-2.03 and sed.

If you need to use a /bin/sh other than bash, you'll need to check your
echo manpage, as many echo's do not accept -n and -e, but bash has a builtin
echo (really nice if you screw up libc), which it will work with.


have fun

greg

-- 
dronf!

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs

Reply via email to