---
title: Writing a Bash Script for GCP to Fetch Data | GSuite Solved
description: Enhance GCP project data retrieval with a robust Bash script. Extract crucial details like project number, folder path, and cost center effortlessly.
image: https://www.c2cglobal.com/hubfs/Imported_Blog_Media/General%20Article%20Graphic-Mar-21-2024-09-11-30-9884-PM-Mar-26-2024-08-41-44-8399-PM.jpg
---

[![c2c logo blue](https://www.c2cglobal.com/hubfs/c2c-logo-blue.svg "c2c logo blue")](https://www.c2cglobal.com/)

[Google Workspace](https://www.c2cglobal.com/articles/tag/google-workspace), [Google Cloud Strategy](https://www.c2cglobal.com/articles/tag/google-cloud-strategy)

# Bash Script for GCP to fetch data

By [Vikash Vikal](https://www.c2cglobal.com/articles/author/vikash-vikal) | November 23, 2021

script to fetch the GCP project details as mention below.

projectid, name, projectnumber, date&time, folderpath, projectowner, folderpath, costcentre, label.

I have written belwo script and it is working for- projectid, name, projectnumber, date&time.

#!/bin/bash

> project\_data.csv

gcloud projects list --format="value(project\_id, name, project\_number, project\_owner, tag, createTime.date(tz=LOCAL))" >whole\_project\_details.txt

echo project\_id, project\_name, project\_number, project\_owner, project\_tag, project\_time >project\_data.csv

while read project\_details

do

project\_id=\`echo $project\_details | awk '{print $1}'\`

project\_name=\`echo  $project\_details | awk '{print $2}'\`

project\_number=\`echo $project\_details | awk '{print $3}'\`

project\_time=\`echo $project\_details | awk '{print $4}'\`

project\_owner=\`echo $project\_details | awk '{print $5}'\`

project\_tag=\`echo $project\_details | awk '{print $6}'\`

echo $project\_id, $project\_name, $project\_number, $project\_owner, $project\_tag, $project\_time  >> project\_data.csv

done < whole\_project\_details.txt

 

But not able to fetch date of - owner, folderpath, label, costcentre.

 

please help me. Thank you in advance.

 

Best Answer from: sathyaram\_s 

 

From the documentation : 

 

> To refer to a list of fields you can sort, filter, and format by for each resource, you can run a list command with the format set to `text` or `json`. For example, $ [gcloud compute instances list](https://cloud.google.com/sdk/gcloud/reference/compute/instances/list) --limit=1 --format=text.

 

In your case, try gcloud projects list --format=text to confirm all the information you are after is available for the project resource. 

---

## Recent Articles

<https://www.c2cglobal.com/articles/generative-ai-are-you-behind>

[Data Analytics](https://www.c2cglobal.com/articles/tag/data-analytics)

## [Generative AI: Are You Behind?!](https://www.c2cglobal.com/articles/generative-ai-are-you-behind)

Review the latest insights from the AI Readiness Report.

By Bruno Aziza

<https://www.c2cglobal.com/articles/make-gen-ai-work-landscape-slms-vs.-llms-cost-more>

[Industry Solutions](https://www.c2cglobal.com/articles/tag/industry-solutions)

## [Make "Gen AI Work": Landscape, SLMs vs. LLMs, Cost & More...](https://www.c2cglobal.com/articles/make-gen-ai-work-landscape-slms-vs.-llms-cost-more)

Discover the 5 metrics you need to know in order to be an exceptional CEO and Operator.

By Bruno Aziza

<https://www.c2cglobal.com/articles/ai-cheat-sheet>

[Google Cloud Strategy](https://www.c2cglobal.com/articles/tag/google-cloud-strategy)

## [AI Cheat Sheet](https://www.c2cglobal.com/articles/ai-cheat-sheet)

AI is no more and no less the drive to create robots with human minds so they can do everything we do and more. Use this cheat sheet to help decode the space.

By Leah Zitter

## Subscribe to our newsletter

Get the latest from C2C, direct to your inbox.

[Subscribe](https://share.hsforms.com/1znKGo6ySS9uaRyvLQQzxRw4qbyr)

![c2c-logo-white-tagline](https://www.c2cglobal.com/hubfs/c2c-logo-white-tagline.svg "c2c-logo-white-tagline")

C2C is the only peer-to-peer community built to support, connect, and educate Google Cloud customers across regions and industries so they can better harness the power of the cloud—and each other—to solve their biggest challenges and drive innovation.

©2024  C2C Global. All rights reserved. [Privacy Policy](https://www.c2cglobal.com/privacy)

20 N Wacker Drive • Suite 1810 • Chicago, IL • 60606

**Join over 60K members on C2C.**

Let's connect!

- [mailto:hello@c2cglobal.com](mailto:hello@c2cglobal.com)
- <https://m.youtube.com/channel/UCWOli-_qQyZziBdPQ-6p-eQ>
- <https://www.linkedin.com/company/66934702>
- [![X](https://www.c2cglobal.com/hubfs/twitter-x-icon-white.svg)](https://twitter.com/MeetC2C)

![](https://px.ads.linkedin.com/collect/?pid=2634489&fmt=gif)