Ivan Podhornyi
Ivan Podhornyi

Reputation: 789

Cut -f parameter not working correctly

I use next command

out=cat /path/myFile | cut -f2,3 -d ',' | sed -r -e 's/,/ /g

myFile looks like:

a1a1a1a1,b1b1b1b1,c1c1c1c1,d1d1d1d1d1
a2a2a2a2,b2b2b2b2,c2c2c2c2,d2d2d2d2d2
a3a3a3a3,b3b3b3b3,c3c3c3c3,d3d3d3d3d3

and after i would got :

b1b1b1b1 c1c1c1c1
b2b2b2b2 c2c2c2c2

but result is write at one line:

b1b1b1b1 c1c1c1c1 b2b2b2b2 c2c2c2c2 ...

Any suggestion?

Upvotes: 2

Views: 113

Answers (2)

naab
naab

Reputation: 1140

You had a quote problem :

out="$(cat /tmp/myfile | cut -f2,3 -d ',' | sed -r -e 's/,/ /g';)"

works and $out have :

b1b1b1b1 c1c1c1c1
b2b2b2b2 c2c2c2c2
b3b3b3b3 c3c3c3c3

Also, for single character replacement, you could use tr

out="$(cat /tmp/myfile | cut -f2,3 -d ',' | tr ',' ' ')"

Then, to use it :

echo "$out"

Upvotes: 1

tripleee
tripleee

Reputation: 189948

Probably you are saying echo $out without quotes instead if the correct

echo "$out"

Upvotes: 2

Related Questions