Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I would like to use awk for a variable that has the form abc,def I also don't know how to use awk for a variable instead of a file I tried the following but it doesn't works
awk -F, '{$1" "$2}' $varand awk -F, '{$1" "$2}' "$var"
awk -F, '{$1" "$2}' $var
awk -F, '{$1" "$2}' "$var"
awk
Use a herestring
awk 'commands' <<< "$string"
Also if you want to print the first two fields of a comma separated string, change the command to
awk -F, '{print $1, $2}' <<< "$string"
Add a comment
You can do something like this:
echo "$variable" | awk -F, '{print $1 " " $2}'
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
awkmay not be the best tool for the job.