This is a test version of Biostars. For the public version, visit https://www.biostars.org.
get variables in two separate lines

I have the file ole.txt:

A   B   C
1   2   3
a   b   c
11  22  33

with option A:

cat ole.txt | sed -n -e 1p -e 3p

we get:

A   B   C
a   b   c

with option B:

sox=$(cat ole.txt | sed -n -e 1p -e 3p)
echo $sox

we get:

A B C a b c

How can I change the code in option B to get the result in option A (the result as 2 rows)?

command line variables

And what's the problem with option A? why you need to keep all the data of a file inside a variable ?!

PS: And I'll tell you, don't play with the white-space characters inside a variable; you are definitely going to burn and it hurts.

PPS: This is happening because the bash shell splits the words on white-space character (spaces, newlines, tabs). I'd recommend not to save data of a file inside a variable. But if you insist, here is the solution

First, I'd use a shorter command. You may check that this command is equivalent

sed -n '1p;3p;' ole.txt

Now

sox="$(sed -n '1p;3p;' ole.txt)"
echo "$sox"

Hello salamandra!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics. try http://unix.stackexchange.com/

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

0 answers

No answers yet.

Log in to answer this question.