shell script required to convert rows to columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script required to convert rows to columns
# 1  
Old 05-06-2008
Bug shell script required to convert rows to columns

Hi Friends,

I have a log file as below


siteid = HYD
spc = 100
rset = RS_D_M
siteid = DEL
spc = 200
rset = RS_K_L
siteid = DEL2
spc = 210
rset = RS_D_M


Now I need a output like column wise as below.

siteid SPC rset
HYD 100 RS_D_M
DEL 200 RS_K_L

Can anybody help me.

Suresh
# 2  
Old 05-06-2008
Check this post may help you
# 3  
Old 05-07-2008
Code:
cat filename  | sed 's/ //g' | nawk 'BEGIN{FS="=";n=1}
{
if($1!="rset")
	a[n$1]=$2
else
{
	a[n$1]=$2
	n=n+1
}
}
END{
print "siteid    spc   rset"
for(i=1;i<=n;i++)
{
	t=sprintf("%ssiteid",i)
	t1=sprintf("%sspc",i)
	t2=sprintf("%srset",i)
	print a[t]"    "a[t1]"   "a[t2]
}
}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

2. Shell Programming and Scripting

Help with script to convert rows to columns

Hello I have a large database with the following structure: Headword=Gloss1;Gloss2;Gloss3 The Glosses are separated by a ; What I need is to reduce the multiple glosses on each row to columns Headword=Gloss1 Headword=Gloss2 Headword=Gloss3 I had written the following script in awk... (5 Replies)
Discussion started by: gimley
5 Replies

3. UNIX for Beginners Questions & Answers

Shell script to convert rows into cloumns

B010215861628 MA 01020 CARRIER B010215861695 MA 01020 CARRIER B010215861709 MA 01020 CARRIER My output is in the above format I want the output to be: (4 Replies)
Discussion started by: Teegela Prathyu
4 Replies

4. Shell Programming and Scripting

Shell script to convert rows to columns

Hi I have a file having the values like below ---------------------------- .set A col1=”ABC” col2=34 col3=”DEF” col4=”LMN” col5=25 .set A .set B col1=55 col3=”XYZ” col4=”PQR” col5=66 .set B .set C col2=”NNN” (1 Reply)
Discussion started by: Suneel Mekala
1 Replies

5. Shell Programming and Scripting

Convert rows to columns

I am looking to print the data in columns and after every 3 words it should be a new row. cat example.out | awk 'END { for (i = 0; ++i < m;) print _;print _ }{ _ = _ x ? _ OFS $1 : $1}' m=1| grep -i INNER I am looking to print in a new line after every 3 words. ... (2 Replies)
Discussion started by: lazydev
2 Replies

6. Shell Programming and Scripting

Convert few columns to rows

Hi! Does anybody help me in converting following data: INPUT looks like this: 20. 100. 30 200. 40. 400. 50. 100. 60. 200. 70. 400. 80. 200. 150. 210. 30. 100. OUTPUT should look like this: 20. 100. 30 200. 40. 400. 50. 100. 60. 200. 70.... (5 Replies)
Discussion started by: lovelinux
5 Replies

7. Shell Programming and Scripting

Convert columns to rows in perl script

Hi All I want to have a Perl script which convert columns to rows. The Perl should should read the data from input file. Suppose the input file is 7215484 date to date 173.3 A 1.50 2.23 8.45 10.14 2.00 4.50 2.50 31.32 7216154 month to month (3 Replies)
Discussion started by: parthmittal2007
3 Replies

8. Shell Programming and Scripting

Converting rows to columns using shell script

I have a script which converts rows to columns. file_name=$1 mailid=$2 #CREATE BACKUP OF ORIGINAL FILE #cp ${file_name}.xlsx ${file_name}_temp.xlsx #tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv #rm ${file_name}_temp.xlsx pivot_row=`head -1 ${file_name}` sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies

9. Shell Programming and Scripting

convert rows to columns

hi, i have the file as below: abc def ghi jkl i want the output as abc,def,ghi,jki please reply, Thanks (4 Replies)
Discussion started by: namitai
4 Replies

10. Shell Programming and Scripting

convert columns into rows

hi, Apologies if this has been covered. I have requirement where i have to convert a single column into multiple column. My data will be like this - 2 3 4 5 6 Output required - 2 3 4 5 6 (1 Reply)
Discussion started by: Nishithinfy
1 Replies
Login or Register to Ask a Question