Script shell on line and row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script shell on line and row
# 1  
Old 07-12-2010
Script shell on line and row

Hello,

I want to make a script to do this :

the file is with line :

Code:
TOTO    TEST1
TOTO    TEST2
TITI      TEST1
TITI      TEST2
TITI      TEST3

i want he become :

Code:
TOTO TEST1 TEST2
TITI  TEST1  TEST2  TEST3

Any idea to do this with script ? i test with awk/sed but dont work

Thanks by advance

safsound
# 2  
Old 07-12-2010
Code:
#!/bin/bash

while read first second
do [ "$first" != "$oldfirst" ] && {
      [ -n "$oldfirst" ] && echo
      oldfirst="$first"
      echo -n "$first $second "
   } || echo -n "$second "
done < File

or
Code:
awk '{ if ( $1 != old ) { if ( old ) { printf "\n" }; old=$1; printf "%s %s ", $1,$2; } else { printf "%s ", $2 };}' File

# 3  
Old 07-13-2010
Quote:
Originally Posted by daPeach
Code:
#!/bin/bash

while read first second
do [ "$first" != "$oldfirst" ] && {
      [ -n "$oldfirst" ] && echo
      oldfirst="$first"
      echo -n "$first $second "
   } || echo -n "$second "
done < File

or
Code:
awk '{ if ( $1 != old ) { if ( old ) { printf "\n" }; old=$1; printf "%s %s ", $1,$2; } else { printf "%s ", $2 };}' File

Very Thanks !!!

Best

Safsound
# 4  
Old 07-13-2010
Code:
awk '{a[$1]=a[$1] FS $2}END{for (i in a) print i,a[i]}' urfile

This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read one row at time using shell script?

Hello Team, I need information on how to read one row at time using shell script. For example i have below data. service-description servername warning critical mountpoint disk-usage-tmp generic-service test1 80 90 /tmp disk-usage-var ... (6 Replies)
Discussion started by: ghpradeep
6 Replies

2. Shell Programming and Scripting

Change col to row using shell script..Very Complex

Hi guys I have file A with Below Data ABC123 X1 X2 X3 ABC123 Y1 Y33 Y4 ABC123 Z1 ZS2 ZL3 ABC234 P1 PP3 PP9 ABC234 Q1 ABC234 R1 P09 PO332 PO331 OKI12 .. .. .. Now I want file B as below ABC123 X1 X2 X3;Y1 Y33 Y4;Z1 ZS2 ZL3 ABC234 P1 PP3 PP9;Q1;R1 P09 PO332 PO331 OKI12... (1 Reply)
Discussion started by: asavaliya
1 Replies

3. Shell Programming and Scripting

How to arrange xml tags in single row using shell script?

I want to put one xml record in one row and so on... sample two records are here. <?xml version="1.0"?> <Object> <Header> <XCOMVers>V1.0</XCOMVers> <REPORT>XXXXX</REPORT> <CODE>002</CODE> </Header> <IssueCard> <Record> <L>CAR SYSTEM -SSSSS -</L> ... (3 Replies)
Discussion started by: sene_geet
3 Replies

4. Shell Programming and Scripting

How to arrange xml tags in single row using shell script?

I want to put one xml record in one row and so on... sample two records are here. <?xml version="1.0"?> <Object> <Header> <XCOMVers>V1.0</XCOMVers> <REPORT>XXXXX</REPORT> <CODE>002</CODE> </Header> <IssueCard> <Record> <L>CAR SYSTEM -SSSSS -</L> ... (1 Reply)
Discussion started by: sene_geet
1 Replies

5. Shell Programming and Scripting

Want to remove the last characters from each row of csv using shell script

Hi, I've a csv file seperated by '|' from which I'm trying to remove the excess '|' characters more than the existing fields. My CSV looks like as below. HRLOAD|Service|AddChange|EN PERSONID|STATUS|LASTNAME|FIRSTNAME|ITDCLIENTUSERID|ADDRESSLINE1 10000001|ACTIVE|Testazar1|Testore1|20041|||... (24 Replies)
Discussion started by: rajak.net
24 Replies

6. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

7. Shell Programming and Scripting

Spliting a row to multiple rows using shell script

Please advice script for changing from A to B I'd like to Split a row to multiple rows with 4 columns using shell script. The data of the file is in one row as below that is 28Mbyte size. A> cto10001 0000000 201010 10:52:13 cto10001 0000000 201011 10:52:13 cto10001 0000000 201011 10:52:13... (2 Replies)
Discussion started by: ianpapa
2 Replies

8. Shell Programming and Scripting

How to do row comparison in shell script

Hi, I need help on doing the below thing in shell script. I have a file with millions of rows called "abc.txt". i have another file with millions of rows called "xyz.txt". I would like to do the below operation. Open the abc.txt, read the first line, do some operations on the column... (2 Replies)
Discussion started by: informsrini
2 Replies

9. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

10. Shell Programming and Scripting

shell script add each row value

Hi, I wrote below small script which will add up each row value from a file and print the total, but it is not.plz let me know what is wrong.script hangs and not displaying anything. ----------------- while read line ; do sum=0; sum=$sum+$line; done echo $sum; exit 0; ------------------... (8 Replies)
Discussion started by: pradeep_script
8 Replies
Login or Register to Ask a Question