name the column based on symbols in another column

Hi
if the input columns (both 2nd and 3rd) are either + or - give the name 1stname. if the 2nd one + and 3rd one - give the name 2ndname and if the 2nd one - and 3rd one + give the name 3rd one as showed in output

Thanx

input

x  +  + some values in other columns
t  -   -  .....
t  +   - .....
g  -  + .....
x  +  + ....   1stname
t  -   -  .....   1stname
t  +   - .....   2ndname
g  -  + .....   3rdname

If you want real quick response, spend some time and give proper data that every one can understand.
Give the input and the expected output.
Is this what you are looking for:

 
echo "x  +  + some values in other columns" | sed "s/..*+  +..*/& 1stname/"

Output

x  +  + some values in other columns 1stname

I think you misunderstood me. I was being simple and precise.

input

x  +  + 100  200
t  -   -  344  333
t  +   - 565  777
g  -  + 789   345

output

x  +  + 100  200  1stname
t  -   -  344  333   1stname
t  +   - 565  777   2ndname
g  -  + 789   345  3rdname

Is it possible to define the columns with specified symbols like
The script is just written roughly so that you guyz can understand

awk '{if ($2 == "+" && $3  == "+") print $0, "1stname"} 
elseif {($2 == "-" && $3  == "-" print $0, "1stname"} 
elseif {($2 == "+" && $3  == "-" print $0, "2ndname"} 
elseif {($2 == "-" && $3  == "+" print $0, "3rdname"}' inputfile

a bit long..

awk '{if ($2$3 == "++" || $2$3 == "--") print $0,"1stname"; 
else if ($2$3 == "+-") print $0,"2ndname";else print $0,"3rdname"}' file

Never mine I solved it myself

$ awk '{if ($2 == "+" && $3  == "+")  print $0, "1stname"}' input.txt && 
awk '{if ($2 == "-" && $3 == "-") print $0, "1stname"}' input.txt && 
awk '{if ($2 == "+" && $3 == "-") print $0, "2ndname"}' input.txt && 
awk '{if ($2 == "-" && $3 == "+") print $0, "3rdname"}'input.txt

---------- Post updated at 08:34 PM ---------- Previous update was at 08:31 PM ----------

Thanx

ryandegreat25

Ok. Then that is exactly what the code does.
I have covered only one part of it, you figure out the rest.
instead of just "sed" use "sed -e " and add the rest.

Shorter :wink:

awk '{$0=$0FS (($2==$3)?1:(($2=="+")?2:3)) "stname"}1' file

nice! :slight_smile: