AWK scripting problem - appending values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK scripting problem - appending values
# 1  
Old 09-30-2005
AWK scripting problem - appending values

ABC:10:A1:ABCA110
ABC:10:A1:ABCA110
ABC:20:A1:ABCA120
DEF:20Smilie1SmilieEFD120
GHI:30:G1:GHIG130
GHI:40:G1:GHIG140
JKL:30:J1:JKLJ130
MNO:10:M1:MNOM110

What I'm trying to do is look through a file that consists of four columns (as above). As you can see there are duplicates in
the file, i.e. line 1 & 2. With this scenario I need to change column three, so the first line appends an 'A' to the
value of 'A1'. And then the second line a 'B' is appended to the value 'A1'. The changed output should look like:

ABC:10:A1A:ABCA110
ABC:10:A1B:ABCA110

If there are more then just two duplicates the appended value should be the next letter of the alphabet, and so on.

How the hell can I do this using awk? I've tried and didn't get remotely close to achieving the above.
# 2  
Old 09-30-2005
This is more difficult than it seems at first.
Code:
BEGIN { FS=OFS=":" }

{
  if ( !Count && prev == $0 )
    Count = 1
  prnt( prev )
  if ( prev != $0 )
    Count = 0
  prev = $0
}

END { prnt( prev ) }  

function prnt( line,     save )
{
  save = $0;  $0 = line
  if ( Count )
    $3 = $3 sprintf("%c", 64 + Count++ )
  print
  $0 = save
}

# 3  
Old 10-03-2005
Wow...thanks for your reply I will give this a go

Thanks very much for you help

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk appending values inside a for loop

Hi i have a 2 files say test1 and test2 with the following data. cat file test test1 i want to append the output from a awk one liner to both the files. for i in cat file;do awk '/ whats happening is its printing the output properly. but not appending the way it showing in print... (1 Reply)
Discussion started by: venkitesh
1 Replies

2. Shell Programming and Scripting

Shell Scripting awk Problem

I'm limited in my skills related to *nix and I'm even more limited in my skills related to shell scripting and the use of awk. I have what should be a relatively simple shell script that looks in the /etc/fstab to see if a particular partition exists on the Linux system. The intention of this part... (2 Replies)
Discussion started by: DisabledVet
2 Replies

3. Shell Programming and Scripting

Assigning array values using awk in shell scripting

hi My script as below #!/bin/ksh for i in `seq 1 7` do a=$(awk '{print $i}' /home/rama/expenese.txt) done for i in `seq 1 7` do echo "${a}" done content of expense.txt is as below 5032 210179 3110 132813874 53488966 11459221 5300794 I want output as... (6 Replies)
Discussion started by: Ramakrishna V
6 Replies

4. Shell Programming and Scripting

Scripting with awk: facing problem

Hi, I wants to print the 9th column information with its path name in some txt file. Here is one line which works fine for me: rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > dataFilenames.list rfdir=="ls -ltr" ... (2 Replies)
Discussion started by: nrjrasaxena
2 Replies

5. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

6. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

7. Shell Programming and Scripting

Problem with lookup values on AWK associative array

I'm at wits end with this issue and my troubleshooting leads me to believe it is a problem with the file formatting of the array referenced by my script: awk -F, '{if (NR==FNR) {a=$4","$3","$2}\ else {print a "," $0}}' WBTSassignments1.txt RNCalarms.tmp On the WBTSassignments1.txt file... (2 Replies)
Discussion started by: JasonHamm
2 Replies

8. Shell Programming and Scripting

problem while adding column values in awk

Hi, I have a file "input.txt" with the following content : 5312,0,,,1,8,141.2,20090727 3714,0,,,1,8,285.87,20090727 5426,0,,,1,8,3.9,20090727 3871,0,,,1,8,30.4,20090727 9071,0,,,1,8,146.2,20090727 5141,0,,,1,8,2.8,20090727 0460,0,,,1,8,-0.1,20090727 7918,0,,,1,8,-0.1,20090727... (3 Replies)
Discussion started by: valokv
3 Replies

9. Shell Programming and Scripting

To Delete the repeated occurances and print in same line by appending values

Hi All, I am trying to work on below text a b c 1 a b c 2 a b c 3 x y z 6 x y z 44 a b c 89 Need to delete the occurances and get in single line like below: a b c 1 2 3 89 x y z 6 44 89 Please help me i am new into unix scripting ..... ---------- Post updated at 03:00... (8 Replies)
Discussion started by: shaliniyadav
8 Replies

10. Shell Programming and Scripting

awk scripting problem

I'm creating an oracle insert statement using awk but need to be able to escape the ' (forward single quote) as the oralce insert syntax requires these quotes. I've tried \ in and out of quotes etc. It's these single quotes values (' .....') cat $1 | awk -F"|" '{print "insert into table... (2 Replies)
Discussion started by: jinky
2 Replies
Login or Register to Ask a Question