Skip to main content
added 366 characters in body
Source Link
ZeroZek
  • 103
  • 3
115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"

My code:

while read line;
 do
 while [[ $var -ne '0' ]];
   do
    var=$( echo $line | cut -d ':' -f$i )
    i=$( expr $i + 1 )
    echo $var
   done
done <$1

I read lines from file and with second while I cut columns until empty one. Obviously, there is something wrong because echo do not print anything.

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"
115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"

My code:

while read line;
 do
 while [[ $var -ne '0' ]];
   do
    var=$( echo $line | cut -d ':' -f$i )
    i=$( expr $i + 1 )
    echo $var
   done
done <$1

I read lines from file and with second while I cut columns until empty one. Obviously, there is something wrong because echo do not print anything.

Formatting
Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324
115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values: My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"



Thanks for your help in advance!

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"



Thanks for your help in advance!

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator.

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"
115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In

In my case, a string consists of 4 columns (every command has :: separator) but it can be much longer. I want to "pull out" allall the commands including initial number, starting with 115115 and continuing with wc -l, -iname "test"wc -l, -iname "*test*", find /tmp/find /tmp/ -iname "*test*" -iname "test"... always without :: separator.
  

My variable $var$var should get those values:
var= 115 , var= wc-l , var= find . -iname "test" , var= find /tmp/ -iname "test"

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"



Thanks for your help in advance!

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "test", find /tmp/ -iname "test"... always without : separator.
 My variable $var should get those values:
var= 115 , var= wc-l , var= find . -iname "test" , var= find /tmp/ -iname "test"

Thanks for your help in advance!

115:wc -l:find . -iname "*test*":find /tmp/ -iname "*test*"

I would like to parse the string above.

In my case, a string consists of 4 columns (every command has : separator) but it can be much longer. I want to "pull out" all the commands including initial number, starting with 115 and continuing with wc -l, -iname "*test*", find /tmp/ -iname "*test*" ... always without : separator. 

My variable $var should get those values:

var= 115 , var= wc-l , var= find . -iname "*test*" , var= find /tmp/ -iname "*test*"



Thanks for your help in advance!

Source Link
ZeroZek
  • 103
  • 3
Loading