I have two text files in tab delimted format like following.
file_1
Entry_1 36372 36414 7 Aa 14956 36371 - Entry_1 36471 36526 3 Aa 14956 36371 -
file_2
Entry_1 36365 36395 - Entry_1 36366 36394 - Entry_1 36367 36395 - Entry_1 36368 36395 - Entry_1 36394 36414 - Entry_1 36471 36502 + Entry_1 36483 36516 + Entry_1 36495 36526 +
these two file contents were stored into two different variables. Now I would like extract the lines which has “+” symbol in column 4 and store it in the variable and later print it. But it throws me error message:
"line 4: /usr/bin/awk: Argument list too long" "line 5: /usr/bin/awk: Argument list too long"
Here is my code which I tried
#!/bin/bash value_1=$(cat file_1.txt); value_2=$(cat file_2.txt); plus="$(awk '$4=="+"' "$value_2" )" minus="$(awk '$4=="-"' "$value_2")" echo "$plus" echo "$minus"
Kindly guide me. I would like extract those entries with which has “+” and “-” symbol and store in variable “$plus” and “$minus”.
Advertisement
Answer
file.1 doesn’t seem to be used. To get the lines to a variable you can do this
$ plus=$(awk '$4=="+"' file.2)
similarly, you can do the same for negative sign.
$ echo "$plus" Entry_1 36471 36502 + Entry_1 36483 36516 + Entry_1 36495 36526 +
if this is what you wanted to achieve.