How to print range of a line?

Hi ,

I have a file content like following. In few lines I have fields with '"' and in few not.

"Country" character varying(150),
    "Region" character varying(60),
    "Total Page Requests" numeric,
    "Pages Served" numeric,
    "Ad request" numeric,
     Ads Served  numeric,
     NFR numeric,
    "Clicks" numeric,
    "CTR" numeric,
    "CPC" numeric,
    "Revenue" numeric,
    "eCPM" numeric

I want to print like following using awk or sed.

"Country"
    "Region" 
    "Total Page Requests"
    "Pages Served"
    "Ad request" 
     Ads Served 
     NFR 
    "Clicks" 
    "CTR" 
    "CPC"
    "Revenue" 
    "eCPM" 

Please help me out.

Thanks in advance.

sed 's/ *\(character\|numeric\).*$//' infile

For sed implementations that don't support alternation:

sed 's/ *character .*//; s/  *numeric.*//' infile

And of course, you should add other data types manually, if necessary.

1 Like
awk -F"character|numeric" '{print $1}' file
1 Like

Hi,
Thanks a ton for your quick response.
Is there any other way to make it dynamic. I don't want to add datatypes explicitly.

For eg. If the line contains quotes print the content along with quotes. Like - "Country"
else print the first column Like - NFR

Thank You

thru sed..

sed -e 's/\(".*"\).*/\1/g' -e 's/ [^ ]*,//' inputfile
1 Like

Thanks a lot.
This worked for me.