On Thu, Apr 17, 2036 at 03:32:47AM -0500, Robert Haehnel wrote:
> I have a tab delimited text file that has 6 field per record. Unfortunately
> the data aquistion program that created this file hiccupped in a few places
> and every so often moved the first to the last position (left shifting the
> whole record). If the first field has been moved I know it because now the
> first field in the record is either 0 or -1.
> 
> So what I'ld like to do is write a quick and dirty script that rips down thru
> the file (record by record), and if it finds a 0 or -1 in the first field it
> yanks the last field back to the beginning where it belongs and right shifts
> all of the other fields in the record. The resulting recodr is still tab
> delimited of course. 
> 
> I have been using sed, but perl or other languages are fine with me. If I have
> to I can write a c++ prog, but I like the brievity of scripts using sed and
> perl for doing various search and replace functions on text files.
        I think awk is more targeted for this. I'll have to think
        about how to do it in sed...

        I don't know how to make an awk script yet, but here's the
        command line that'll do it (I think)(seems to work here).

awk 'BEGIN{FS=OFS="\t";}{if ($1 == "0"||$1 == "-1"){print 
$6,$1,$2,$3,$4,$5;}else{print;}}' < file

have fun

greg
(I'll think about sed soon)
-- 
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