LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-17-2012, 08:40 AM   #1
Sankaran29
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Rep: Reputation: Disabled
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.

Thanks in advance!!
 
Old 12-17-2012, 09:10 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Hello Sankaran29, welcome to LQ,

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.

Markus
 
Old 12-17-2012, 09:24 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.

Last edited by shivaa; 12-17-2012 at 09:26 AM.
 
Old 12-17-2012, 09:49 AM   #4
Sankaran29
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
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

Thanks for responding .
 
Old 12-17-2012, 09:57 AM   #5
Sankaran29
LQ Newbie
 
Registered: Dec 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Need CSV output report with all 147 lines with some fixed width
 
Old 12-17-2012, 10:29 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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:
Code:
awk '/Exception/; {gsub(/,/,".",$0}; print $0}' Logfile.txt >  temp.out
I did not get why you converted "," into "."? Are entries "," sepearte in logfile?
 
Old 12-17-2012, 10:33 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to script csv editing? Remove rows from csv file that do not contain certain text ingram87 Linux - Software 9 08-03-2012 01:45 PM
Filling text with fixed column width. polch Linux - General 2 09-02-2011 11:34 AM
Import fixed-width column text document in OpenOffice.org Calc Marel Linux - Desktop 3 05-05-2008 04:23 PM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 03:36 PM
loading from text file using column width spyghost Programming 5 11-03-2003 02:34 PM


All times are GMT -5. The time now is 05:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration