awk to print value from txt file to csv

Hi,

I want to print two columns from a .txt file to a .csv file using awk.

data in text file:

Application
-------------------------------------------------- -----------
OS Related Issues 1
EMEA Solutions 9
Global Solutions 2

what i want to print is:

OS Related Issues,1
EMEA Solutions,9
Global Solutions,2

Please suggest some way to get this done. I'm new to shell scripting and m not really familiar with awk. :frowning:

Thanks in advance.

FYI: working on ksh

$ awk '{for(i=1;i<NF;i++){printf("%s ",$i)} printf(",%s\n",$NF)}' test.txt 
OS Related Issues ,1
EMEA Solutions ,9
Global Solutions ,2

---------- Post updated at 01:39 PM ---------- Previous update was at 01:25 PM ----------

$ awk '$NF=","$NF' test.txt
OS Related Issues ,1
EMEA Solutions ,9
Global Solutions ,2
1 Like

is there any way to skip the first two lines and display values from the 3rd line..??

the text file starts with:

Application
-------------------------------------------------- -----------

i want to remove the first two lines and get values from the 3rd line.. is that possible..??

you can use

 
if ( NR >= 3 )

If the additional blank is/was no problem you can try:

$> awk 'NR>2 {$NF=","$NF; print}' infile
OS Related Issues ,1
EMEA Solutions ,9
Global Solutions ,2
1 Like

that worked fine.. one last question (i know i should have asked this earlier), how do i avoid the last line in that file..? sorry for bothering..

With a little adjustment of zaxxon's code:

awk 's{print s} NR>2 {$NF=","$NF; s=$0}' infile

this throws error..

awk: syntax error near line 1
awk: bailing out near line 1

Use nawk or /usr/xpg4/bin/awk on Solaris.