LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   parsing out from rpm -qa --queryformat into CSV output (https://www.linuxquestions.org/questions/linux-newbie-8/parsing-out-from-rpm-qa-queryformat-into-csv-output-4175546848/)

JCDinPGH 06-30-2015 03:37 PM

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?

berndbausch 06-30-2015 09:16 PM

Quote:

Originally Posted by JCDinPGH (Post 5385250)
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.

JCDinPGH 07-01-2015 07:22 AM

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 (Post 5385382)
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 (Post 5385382)
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.


syg00 07-01-2015 07:37 AM

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.

JCDinPGH 07-01-2015 08:51 AM

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 (Post 5385594)
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.



All times are GMT -5. The time now is 08:32 PM.