The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare 2 sorted files varungupta Shell Programming and Scripting 7 01-25-2008 01:07 PM
sorted processes pro Shell Programming and Scripting 7 05-19-2007 04:52 AM
Need to display sorted output on 1 line! knc9233 UNIX for Dummies Questions & Answers 2 01-17-2007 10:26 PM
Trying to get list of logged on users sorted kungfuice Shell Programming and Scripting 7 07-26-2006 03:35 PM
comm - sorted result issues krsunderm UNIX for Dummies Questions & Answers 1 11-29-2005 07:36 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 10-24-2007
buddyme buddyme is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 11
Inserting in sorted rows

Hello Friends,

I have a file with many many rows and I want to insert some numbers in between numbers.
The number must be inserted in "correct sorted order".

1. Input = 1055555

0000001
1000000
1055555 <-insert here
3000000
4000000
5000000
8000000

2. Input = 4000080
0000001
1000000
3000000
4000000
4000080 <-insert here
5000000
8000000

Do you have other solutions aside from this?

cat 1055555 >> Onerow.txt
sort Onerow.txt

Thank you my friend.
  #2 (permalink)  
Old 10-24-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915

Code:
awk '!f&&$1>n{$0=n"\n"$0;f=1}1' n="$input" filename

Use nawk or /usr/xpg4/bin/awk on Solaris.

So, you should:

Code:
awk '!f&&$1>n{$0=n"\n"$0;f=1}1' n="$input" filename>new\
&&cp filename filename.orig\
&&mv new filename

For input greater than the max value in the file:

Code:
awk '!f&&$1>n{$0=n"\n"$0;f=1}1;END{if(!f)print n}' n="$input" filename


Last edited by radoulov; 10-24-2007 at 06:37 AM..
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 10: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