need shell command to wrap text &adjust column width (csv file )
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
need shell command to wrap text &adjust column width (csv file )
Hi!
I've written a shell script to monitor the log file and output the lines which include "exception" pattern in it.
I'm receiving the report in csv format via mail .The problem is with csv report format (Lines are too long ). Evrytime i open the report , have to manually adjust the column width and wrap text it. (Alignment--->Text control --> wrap text).
Please let me know if thr is any command in shell to adjust column width and wraptext the csv report before emailing it.
which tools do you use in your shellscript? afaik the printf function in AWK works similar as in C, so it should be possible, to format the output with AWK. It is explained in the manpage for AWK.
For more help, please post your script and some example output.
Does that report contains lot of CSV, which are not wrapped? Once share sample file plus output that you want. It then can be easily formatted with awk in desired way.
grep i "Exception" Logfile.txt > Temp.out
sed s/,/\./g <Temp.out | awk -f '{Printf $1}' > Temp.csv
unencode and mailx commands to send the output csv to my mail id
sorry i'm not allowed to upload files from my wks.
my output Temp.csv file contains 147 long lines with exceptions like Rollback ,sqlsyntax exceptions ... with different column width eg: Column A1 width is more than 170 Column A2 line width is 75 ,A3 :180 till ... A147
Perhaps you've trying to copy the data of temp.csv into excel sheet to adjust columns. But to be honest, it's really tough to answer without knowing the exaxt input file pattern and output pattern. Although it can be done using awk, but as I said, it's still not clear.
Once share a sample (just dummy entries, but exactly in same format as it is in temp.out file). In the meantime, commands your using can be shortend as:
There is no standard way to split an individual field of a CSV file; any algorithm to do so would be completely domain-specific. Given that, it is unlikely that anyone can guess how to to split your data. You don't have to upload files to provide sample data, just copy/paste some representative data into your posting. Use [CODE][/CODE] tags (vital) to preserve formatting so people can suggest parsers that actually work.
--- rod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.