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.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 08:30 AM
Sorting in C++.. ronix007 High Level Programming 6 03-06-2008 05:16 PM
Sorting/Filed Defining/Output problem TiredOrangeCat Shell Programming and Scripting 1 02-12-2007 12:41 AM
Sorting problem "sort -k 16,29 sample.txt > output.txt" ganapati Shell Programming and Scripting 3 08-01-2006 06:55 AM
Sorting "ls" output on more than 1 column Nicol UNIX for Dummies Questions & Answers 1 09-20-2005 08:37 AM

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 01-08-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 431
sorting output

hi,

I get an output like

uid=user1
gecos=user

uid=user2
gecos=admin

gecos=sol admin
uid=user3

uid=user4
gecos=sol, admin

and need it modified to:

uid=user1
gecos=user

uid=user2
gecos=admin

uid=user3
gecos=sol admin

uid=user4
gecos=sol, admin

the file has about 180 lines and ~4 paragraphs are not in correct order

thanks alot in advance

funksen
  #2 (permalink)  
Old 01-08-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
$ cat datafile
uid=user1
gecos=user

uid=user2
gecos=admin

gecos=sol admin
uid=user3

uid=user4
gecos=sol, admin

$ cat scr
#! /usr/bin/ksh

awk  '  /^uid/ { u=$0 }
        /^gecos/ { g=$0 }
        /^$/  { print ; print u ; print g }'
$ ./scr < datafile

uid=user1
gecos=user

uid=user2
gecos=admin

uid=user3
gecos=sol admin

uid=user4
gecos=sol, admin
$

  #3 (permalink)  
Old 01-09-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
sed "/^gecos/{N;s/\(.*\)\n\(uid=.*\)/\2\\
\1/;}" file

  #4 (permalink)  
Old 01-09-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 431
great job, both are working perfectly

many thanks

cheers funksen
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:51 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