The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
convert columns into rows Nishithinfy Shell Programming and Scripting 1 07-06-2009 12:16 PM
convert rows into columns loperam Shell Programming and Scripting 2 12-01-2008 03:57 AM
how to convert columns to rows suresh3566 Shell Programming and Scripting 6 11-04-2008 08:20 AM
How to convert a single column into several rows and columns? ashton_smith UNIX for Dummies Questions & Answers 5 05-24-2008 05:44 PM
convert rows into column cdfd123 Shell Programming and Scripting 3 01-11-2008 12:54 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-15-2009
akil akil is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 50
convert rows to single row

Hi
I want to convert multiple rows ro single row ,I have tried with below one but I am not getting what I am expecting.Please any idea

Code:
a.txt

[a.s1.txt]
conn1=stg
conn2=dev
path=\xxx\a1.txt
fre=a

[a.s2.txt]
conn1=stg
conn2=dev
path=\xxx\a2.txt
freq=a


awk '/a/{ORS=" "}{print}END{print "\n"}' a.txt


[a.s1.txt] conn1=stg conn2=dev path=\xxx\a1.txt fre=a   [a.s2.txt] conn1=stg conn2=dev path=\xxx\a2.txt freq=a


I am expecting the below

[a.s1.txt] conn1=stg conn2=dev path=\xxx\a1.txt fre=a

[a.s2.txt] conn1=stg conn2=dev path=\xxx\a2.txt freq=a

Thanks,
Akil
  #2 (permalink)  
Old 10-15-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Try this:


Code:
awk '$1=$1' RS= OFS=" " ORS="\n\n" a.txt

  #3 (permalink)  
Old 10-15-2009
akil akil is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 50
Hi
Thanks,Its working fine


Akil

---------- Post updated at 02:16 AM ---------- Previous update was at 02:09 AM ----------

Hi
Sorry ,I have got the below error when call this

awk '$1=$1' RS= OFS=" " ORS="\n\n" a.txt1
awk: Input line [a.Addr cannot be longer than 3,000 bytes.
The source line number is 1.


I found the problem,there is no space between s1.txt s2.txt lines,Please any idea how to create the space

[a.s1.txt]
conn1=stg
conn2=dev
path=\xxx\a1.txt
fre=a
[a.s2.txt]
conn1=stg
conn2=dev
path=\xxx\a2.txt
freq=a


Thanks,
Akil

Last edited by akil; 10-15-2009 at 04:25 AM..
  #4 (permalink)  
Old 10-15-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Try:


Code:
awk '/\[/ {printf("%s%s",NR>1?"\n":"",$0);next}
{printf(" %s",$0)}
END{print ""}' file

  #5 (permalink)  
Old 10-15-2009
akil akil is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 50
Hi
Its workin fine.Thanks for your help

Thanks,
Akil
  #6 (permalink)  
Old 3 Weeks Ago
akil akil is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 50
Hi
I want to add connection parameter value in each entry

Code:

[a.s1.txt]
conn1=stg
conn2=dev
path=\xxx\a1.txt
fre=a
[a.s2.txt]
conn1=stg
conn2=dev
path=\xxx\a2.txt
freq=a

EXPECTING O/P


[a.s1.txt]
conn1=stg
conn2=dev
path=\xxx\a1.txt
fre=a
connection=SRC
[a.s2.txt]
conn1=stg
conn2=dev
path=\xxx\a2.txt
freq=a
connection=SRC

Thanksinadvance
Akil
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0