Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

How would you separate fields with multiple spaces and store them in an array?

$
0
0

For example :

In my file mytxt

field1                    field2
------                    -------
this are numbers          12345
this letters              abc def ghi 

Let's say I want to store the first field in an array

i=0
while read line; do 
    field_one[$i]=$(echo $line | awk '{print $1}')
    echo ${field_one[i]}  
    ((i++))
done < mytxt

That would give me the "this" 2 times in the output

Any ideas of how could I store them in an array and get The output:

this are numbers      
this letters      

I have tried changing delimeters , squeezing spaces , and using sed but I'm stuck. any hint would be aprecciate it .

My final goal is to store both fields in an array.


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>