LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Blogs > karanis
User Name
Password

Notices


Rate this Entry

BASH extract fields from string

Posted 04-05-2020 at 05:19 PM by karanis
Tags awk, bash

https://en.wikibooks.org/wiki/Cut

link above have nice examples

Examples of use of similar tools in cut's domain:

echo a b|awk '{print $2}'
Displays "b", separating fields by any number of tabs or spaces. Thus, for awk, "b" is the 2nd field, while for cut -d" ", "b" is the 3rd field.
echo a b|awk '{print $2 $1}'
Displays "ba", preserving the order of the fields as specified.
echo a b|sed "s/ */ /g" |cut -f2 -d" "
Displays "b". Uses sed to first compact a sequence of spaces into a single space.
Posted in Uncategorized
Views 50 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 04:24 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration