The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
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 08-19-2008
m_mouse m_mouse is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Help with awk

Hi
I have a question regarding awk.
I have a file that contains several lines:
/dev/vg1
/dev/blabla
/dev/vg01
/dev/blabla2
i need to merge a lines as following:
/dev/vg1:/dev/blabla
/dev/vg01:/dev/blabla2
Can somebody help me?
  #2 (permalink)  
Old 08-19-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
paste -d":" - - < your_filename_here
  #3 (permalink)  
Old 08-19-2008
m_mouse m_mouse is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
not working,
by the way the file can be appear as follows too:
/dev/vg1
/dev/blabla
/dev/vg01
/dev/blabla2
/dev/blabla3
/dev/blabla4

and it need to be composed as follows:
/dev/vg1:/dev/blabla
/dev/vg01:/dev/blabla2:/dev/blabla3:/dev/blabla4
  #4 (permalink)  
Old 08-19-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
while read line
do
curr=`echo $line |grep -i "vg"|wc -l|awk '{print $1}'`
if [ "$curr" = "1" ]
then
echo "\n$line\c"
else
echo ":$line\c"
fi
done < your_file_here
  #5 (permalink)  
Old 08-19-2008
m_mouse m_mouse is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 4
Thanks working
  #6 (permalink)  
Old 08-19-2008
sudhamacs sudhamacs is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 98
awk 'ORS=NR%2?":":"\n"' file
  #7 (permalink)  
Old 08-19-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,910
Tested with GNU Awk (I believe it should work with nawk on Solaris too):

Code:
 
awk -F: '$0=/\/vg/?(!x++?y:RS)$0:FS$0' ORS= filename
Closed Thread

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 01:41 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