i have this string
-foo {{0.000 0.000} {648.0 0.000} {648.0 1980.0} {0.000 1980.0} {0.000 0.000}}
i want to separate it to numbers and iterate over them ,thanks tried to use Field separator without success how can i do it with awk?
As you can see, you can combine more than one delimiter in the AWK field separator to get specific information.
The variable FS is used to set the input field separator. In awk , space and tab act as default field separators. The corresponding field value can be accessed through $1 , $2 , $3 ... and so on. -F - command-line option for setting input field separator.
awk programming -Passing variable to awk for loop awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... Discussion started by ctrld and has been viewed 2,402 times.
Just put your desired field separator with the -F option in the AWK command and the column number you want to print segregated as per your mentioned field separator.
Try doing this :
awk -F'}+|{+| ' '{for (i=1; i<=NF; i++) if ($i ~ "[0-9]") print $i}' file.txt
The Field Separator FS
(the -F
switch) can be a character, a word, a regex or a class of characters.
You can use this too :
awk 'BEGIN{FS="}+|{+| "} {for(i=1;i<=NF;i++) if($i ~ "[0-9]")print $i}' file.txt
foo|bar|base
is a regex where it can match any of the strings separated by the |
}+|{+|
, we have the choice to match a literal }
at least one : +
, or a literal {
at least one : +
, or a space.[{} ]
, both worksIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With