Change names in a column based on the symbols in another column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change names in a column based on the symbols in another column
# 1  
Old 08-11-2009
Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output).

Thanx

input1

Code:
1    a    aaaaa    +
2    b    bbbbb    +
3    c    ccccc    +
4    d    ddddd    +
5    e    eeeee    +
6    f    xxxxx    +
8    h    hhhhh    +
9    a    aaaaa    -
10    b    bbbbb    -
11    c    ccccc    -
12    d    ddddd    -
13    e    eeeee    -
14    f    xxxxx    -
15    g    ggggg    -
16    h    hhhhh    -

output

Code:
1    a    aaaaa    +
2    b    bbbbb    +
3    c    ccccc    +
4    d    ddddd    +
5    e    eeeee    +
6    f    xxxxx    +
8    h    hhhhh    +
9    a    ppppp    -
10    b    qqqqq    -
11    c    rrrrr    -
12    d    sssss    -
13    e    ttttt    -
14    f    uuuuu    -
15    g    vvvvv    -
16    h    yyyyy    -



---------- Post updated 08-11-09 at 12:18 AM ---------- Previous update was 08-10-09 at 11:53 PM ----------

I'm trying some thing like this

Code:
awk '($5 ~ /-/) {print $0} else {print}' input | tr 'aaaaa,bbbbb,ccccc,ddddd,eeeee,fffff,xxxxx,hhhhh' 'ppppp,qqqqq........................

But this only prints the values with negative sign. I need some thing like the output I mentioned above
# 2  
Old 08-11-2009
what do u mean by user defined names???
And u have 4 columns in the input file as u mentioned up and u r comparing the minus sign with the 5th column which u dont have it in ur inputfile as u mentioned up.
# 3  
Old 08-11-2009
user defined names like ppppp or qqqqq etc.
Sorry thats 4th column
Code:
awk '($4 ~ /-/) {print $0} else {print}' input | tr 'aaaaa,bbbbb,ccccc,ddddd,eeeee,fffff,xxxxx,hhhhh' 'ppppp,qqqqq........................

# 4  
Old 08-11-2009
where have u defined those user defined names???
# 5  
Old 08-11-2009
Code:
awk '($4 ~ /-/) {print $0} else {print}' input | tr 'aaaaa,bbbbb,ccccc,ddddd,eeeee,fffff,xxxxx,hhhhh' 'ppppp,qqqqq,rrrrr,ssssss,ttttt,uuuuu,vvvvv,yyyyy'

The bold ones are user defined
# 6  
Old 08-11-2009
what i suggest is that u better store those user defined names in a separate file and when ever u find a minus sign, replace that field.
but also u should have some common column so u can know which column to replace with which one.
# 7  
Old 08-11-2009
Yes you are right But I' m afraid i dont know how to write the code for 2 files
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies

2. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

3. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

4. UNIX for Dummies Questions & Answers

Find the average based on similar names in the first column

I have a table, say this: name1 num1 num2 num3 num4 name2 num5 num6 num7 num8 name3 num1 num3 num4 num9 name2 num8 num9 num1 num2 name2 num4 num5 num6 num4 name4 num4 num5 num7 num8 name5 num1 num3 num9 num7 name5 num6 num8 num3 num4 I want a code that will sort my data according... (4 Replies)
Discussion started by: FelipeAd
4 Replies

5. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

6. Shell Programming and Scripting

to add special tag to a column based on column condition

Hi All, I have following html code <TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR> <TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR> <TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
Discussion started by: ckwan
9 Replies

7. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

8. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

9. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

10. Shell Programming and Scripting

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 + ... (7 Replies)
Discussion started by: repinementer
7 Replies
Login or Register to Ask a Question