-
-
Save jazzsequence/97a7b7efc569bfb201fa4070972eefd5 to your computer and use it in GitHub Desktop.
ChatGPT get_field bash function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------ ---------------------------------------------- | |
ID 1234d12a-1d12-12b1-1234-123e1234a123 | |
Name some-misc-slug | |
Label Some Misc Name | |
Created 2022-11-29 21:45:09 | |
Framework wordpress | |
Region United States | |
Repository 12b123ab-0e12-34dc-a56d-fd7890bb1234: | |
https://github.com/jazzsequence/jazzsequence.github.io.git | |
------------------ ---------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_field() { | |
# $1: field name | |
# $2: input string | |
echo "$2" | awk -v field="$1" '$1 == field { print $2 }' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_field() { | |
local input="$1" | |
# Remove leading and trailing whitespace from each line | |
input="$(echo "$input" | sed -e 's/^[ \t]*//')" | |
# Remove the first and last lines that are entirely dashes | |
input="$(echo "$input" | sed -e '1d' -e '$d')" | |
# $1: field name | |
# $2: input string | |
echo "$2" | awk -v field="$1" '$1 == field { print $2 }' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extract the ID and Name fields | |
id=$(get_field "ID" "$input") | |
name=$(get_field "Name" "$input") | |
# Print the extracted values | |
echo "ID: $id" | |
echo "Name: $name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment