dynamic values in a row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dynamic values in a row
# 1  
Old 11-02-2011
dynamic values in a row

hi
i have an input file in which there are diffrent values for xxxx,yyyyyy,zzzzzzz how can i arrange the dynamic values of x,y&z in a row.

input file:
Code:
xxxxx 1
yyyyyy 4
yyyyyy 5
zzzzzzzz 7
yyyyyy 13
zzzzzzzz 7
zzzzzzzz 6
yyyyyy 14
yyyyyy 12
zzzzzzzz 4
yyyyyy 4
yyyyyy 5
yyyyyy 6
yyyyyy 15
yyyyyy 7
zzzzzzzz 12
zzzzzzzz 14
zzzzzzzz 13
zzzzzzzz 15
zzzzzzzz 5
xxxxx 1

output:
Code:
xxxxx 1,1
yyyyyy 4,14,5,6,15
zzzzzzzz7,7,6,4,12,14,15

Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 11-02-2011 at 07:08 AM.. Reason: code tags, see PM
# 2  
Old 11-02-2011
I do not understand the logic:

Quote:
yyyyyy 4,14,5,6,15
Code:
grep y infile| cut -d" " -f2| sort -nu
4
5
6
7
12
13
14
15

There seem to be missing values.
# 3  
Old 11-02-2011
Anyway maybe this is what you are looking for:
Code:
$> awk '{_[$1] ? _[$1]= _[$1] OFS $2 : _[$1]= $2} END{for(a in _){print a " " _[a]}}' OFS=, infile
yyyyyy 4,5,13,14,12,4,5,6,15,7
xxxxx 1,1
zzzzzzzz 7,7,6,4,12,14,13,15,5

# 4  
Old 11-02-2011
it gave me output:
Code:
,55zzz 7
,75yyy 4
,1xxxx 1

please suggest:

Moderator's Comments:
Mod Comment Use code tags - check your PMs. Also stop sending me PMs to get a solution. If you continue to act this way, you will be banned soon; consider this. Here are the forum rules: Forum Rules

Last edited by zaxxon; 11-02-2011 at 08:43 AM..
# 5  
Old 11-02-2011
What OS are you using?
# 6  
Old 11-03-2011
its sun solaris 5.9

---------- Post updated at 09:35 PM ---------- Previous update was at 09:35 PM ----------

i need it urgently ... plz help
# 7  
Old 11-03-2011
Use nawk and try if solaris.

Code:
[root@bt] $ uname -a
SunOS 5.8 xxxxxxxxxxxxxxxxxxx
[root@bt]  $ nawk '{_[$1] ? _[$1]= _[$1] OFS $2 : _[$1]= $2} END{for(a in _){print a " " _[a]}}' OFS=, f
xxxxx 1,1
yyyyyy 4,5,13,14,12,4,5,6,15,7
zzzzzzzz 7,7,6,4,12,14,13,15,5

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut command with dynamic passing of delimiter and position values

Hi All, We have a requirement of picking nth position value by using cut command. value would be delimited by any symbols. We have to pass delimited value and postition to get the value in a string. ex. echo "A,B,C,D,E" |cut -d "," -f3 echo "A|B|C|D|E"|cut -d "|" -f2 Kindly frame the... (5 Replies)
Discussion started by: KK230689
5 Replies

2. Shell Programming and Scripting

Replace sql with dynamic values

Hi Guys, I am using a function to replace the values dynamically to frame sql query by reading a file. My file will have column names like file.txt col_1 col_2 expected output: select id,col_1,col_2 from ( select a.id, a.col_1, rank() over (ORDER BY cast(a.col_1 AS double)... (5 Replies)
Discussion started by: Master_Mind
5 Replies

3. Shell Programming and Scripting

How to lowercase the values in a column in awk and include a dynamic counter?

Hi, I am trying to incorporate 2 functions into my `awk` command. I want to lower case Column 2 (which is essentially the same information in Col1, except in Col1 I want to maintain the capitalization) and I want to count from 0-N that begins and ends with the start of certain markers that I... (6 Replies)
Discussion started by: owwow14
6 Replies

4. Shell Programming and Scripting

Keep 3 values in each row

Hi, I have n number of values like 1 2 3 4 I want the output like 1 2 3 4 5 6 - - - - - - Please help me on this:wall: (4 Replies)
Discussion started by: cns1710
4 Replies

5. Shell Programming and Scripting

Using dynamic arrays to extract the values

Hi all, We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING") Based on indicator files produced while processing data for each type, we need to get the stats (using... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

6. Shell Programming and Scripting

Assigning values to reference variables for a dynamic menu driven script.

How do I assign values to reference variables? I am assigning a variable name to --> $user_var Then I am trying to change its underlying variable value by $((user_var))=$user_value .. its failing,, Please let me know if there is a way to do this dynamically.. FileA.props... (5 Replies)
Discussion started by: kchinnam
5 Replies

7. Shell Programming and Scripting

Assigning values for a dynamic array for an input

Hello, Can somebody please give me a snippet for the below requirement. I want to assign the values separeted by a comma to be assigned to a dynamic array. If I give an input (read statement) like abc1,abc2,abc3,abc4,abc5, all these strings abc* should be assigned to an array like below... (2 Replies)
Discussion started by: suneelj
2 Replies

8. Shell Programming and Scripting

Extracting dynamic values

Hi, I am stuck with extracting values by combining 2 dynamically extracted values. The code goes like this #!/usr/bin/ksh ID1="abcd" i=1 #this is a dynamic value and keeps on changing b="ID" #this is static now i want the value of ID1 variable. like echo $b$i But echo... (1 Reply)
Discussion started by: chaitanyapn
1 Replies

9. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

10. UNIX for Dummies Questions & Answers

Dynamic variable values

Bit of a newbie :D with regard to unix scripting and need some advice. Hopefully someone can help with the following: I have a predefined set of variables as follows: AAA_IP_ADD=1.1.1.1 BBB_IP_ADD=2.2.2.2 I have a funnction call which retrieves a value into $SUPPLIER which would be... (3 Replies)
Discussion started by: ronnie_uk
3 Replies
Login or Register to Ask a Question