Columns - the end (so you thought) :)
MYERS
ufpsprod!gmyers at atlml1.attmail.com
Thu Feb 22 12:17:32 EST 1996
} Thanks to all who answered. It is interesting to me how often strings
} and string manipulation are the subject of problems and questions in
} the C-Unix environment.
}
} To summarize:
}
} Problem: convert "every | good | boy | does | fine" to
}
} every
} good
} boy
} does
} fine
}
} Answers: Consensus seemed to be to use sed to strip whitespace.
} Then to add newlines:
}
} 1 ) gawk
}
} awk -F\| '{for (i=0;i<=NF;i++) {printf "%s\n,$i}}'
}
} 2) tr
}
} tr '|' '\012'
}
} 3) fmt
}
} sed 's/|//g' | fmt -1
}
} I guess I liked #2 myself. #1 seemed a little obtuse. #3 might cause
} problems with fields that contained whitespace in their midst.
} Thanks again!
}
} Regards - Jim
} --
} James N. McClatchey P.E. (Southern Aluminum Finishing Co, Atlanta, GA, USA)
} Architectural Aluminum. Custom Fabrication. Paint, Powder Coating, Anodizing
} mailto:jnm at saf.com Voice: 404-355-1560 Fax: 404-350-0581
} http://www.saf.com SAF Home Page
Just like a programmer, I can't let this one go. I didn't consider
fields with imbedded white space in the original solution because the
specs didn't specify as such. :) Anyway, I propose yet another (g)awk
solution that will address this concern:
nawk -F'|' '{for (i=0;i<=NF;i++) {
gsub("^[ \t]", "", $i)
gsub("[ \t]$", "", $i)
printf "%s\n",$i}
}' foo
$ cat foo
this | is | a true | statement
Now this is using nawk on SunOS, but I'd be willing to bet a good beer that
this will work under LINUX. Just had to get my last test in. :)
Until later, attmail!gamyers ph 404.810.3250
Geoffrey Myers fax 404.810.2487
floc 6E26, 1200 Peachtree, Promenade II, Atlanta, GA 30309
gamyers at attmail.com geof at denali.is.net eiger at ichange.com
More information about the Ale
mailing list