LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-30-2015, 03:37 PM   #1
JCDinPGH
LQ Newbie
 
Registered: Jun 2015
Location: Pittsburgh, PA
Posts: 3

Rep: Reputation: Disabled
parsing out from rpm -qa --queryformat into CSV output


I found several different web sites talking about this but my problem is slightly different and I haven't been able to find an answer anywhere. When querying the RPM database usin TAGS like
rpm -qa --qf '%{NAME} %{VERSION}.%{RELEASE} %{SUMMARY} %{VENDOR} %{DESCRIPTION} %{INSTALLTIME:date}\n'
I get tabbed output I am looking for except the output from the DESCRIPTION tag contains LF characters so when importing it into an excel spreadsheet, every line from the DESCRIPTION tags causes a new line. I'm looking for the the ability to run the above RPM command and have the output from each of the TAGS separated by tabs with no cr or lf so they will correctly import into a spreadsheet where each TAG has it's own column. I've tried using tr to change \n to a space (|tr '\n' ' ') but then all of the output is one continuous line. I think I'm close but just can't quite see it.
Thoughts?
 
Old 06-30-2015, 09:16 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by JCDinPGH View Post
I found several different web sites talking about this but my problem is slightly different and I haven't been able to find an answer anywhere. When querying the RPM database usin TAGS like
rpm -qa --qf '%{NAME} %{VERSION}.%{RELEASE} %{SUMMARY} %{VENDOR} %{DESCRIPTION} %{INSTALLTIME:date}\n'
I get tabbed output I am looking for except the output from the DESCRIPTION tag contains LF characters so when importing it into an excel spreadsheet, every line from the DESCRIPTION tags causes a new line. I'm looking for the the ability to run the above RPM command and have the output from each of the TAGS separated by tabs with no cr or lf so they will correctly import into a spreadsheet where each TAG has it's own column. I've tried using tr to change \n to a space (|tr '\n' ' ') but then all of the output is one continuous line. I think I'm close but just can't quite see it.
Thoughts?
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.

You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
 
Old 07-01-2015, 07:22 AM   #3
JCDinPGH
LQ Newbie
 
Registered: Jun 2015
Location: Pittsburgh, PA
Posts: 3

Original Poster
Rep: Reputation: Disabled
The output from each TAG (NAME,VERSION,SUMMARY etc) is currently separated by a tab and has no lf in the output. The DESCRIPTION output, because it can be longer,does have lf in the output so when attempting to input it into Excel or similar, the DESCRIPTION output ends up taking up multiple cells instead of just using one cell in the spreadsheet like all of the other TAGS. I'd like to be able to strip the lf from the DESCRIPTION output only. That way all of the TAGS would be on one line but separated by TABS so they would successfully import into Excel. I will play around with SED and see what I can come up with.

Quote:
Originally Posted by berndbausch View Post
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.

You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
Quote:
Originally Posted by berndbausch View Post
So you want to remove line feeds but don't want the output to be on a single line? To me, this is a contradiction.

You might be more successful by putting double quotes around the %{DESCRIPTION}, hoping that there are no double quotes inside the %{DESCRIPTION}. Should be feasible with a pipeline of sed commands - first convert double quotes to something else, then add them around the description.
 
Old 07-01-2015, 07:37 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
If you got rid of the DESCRIPTION and only used the SUMMARY (why both anyway), you might find the problem goes away.
I had a play using awk, but it could get ugly.
 
Old 07-01-2015, 08:51 AM   #5
JCDinPGH
LQ Newbie
 
Registered: Jun 2015
Location: Pittsburgh, PA
Posts: 3

Original Poster
Rep: Reputation: Disabled
Removing the DESCRIPTION TAG definitely removes the problem as it's the only output with lf in it. I was just keeping the DESCRIPTION tag because it provides a lot more detail.
Quote:
Originally Posted by syg00 View Post
If you got rid of the DESCRIPTION and only used the SUMMARY (why both anyway), you might find the problem goes away.
I had a play using awk, but it could get ugly.
 
  


Reply



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] Parsing CSV data in CentOS panic Linux - Newbie 8 07-08-2013 09:44 AM
Parsing a ..csv file devnull10 Programming 6 06-20-2013 03:15 AM
Help with simple CSV parsing nilleso Programming 10 09-22-2010 11:23 PM
Parsing a pseudo CSV file. sharky Programming 8 11-03-2008 10:47 PM
rpm queryformat avijitp Linux - Software 2 04-23-2007 10:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:02 AM.

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
Open Source Consulting | Domain Registration