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
reversing order of lines in a file gfhgfnhhn Shell Programming and Scripting 26 07-30-2009 09:01 AM
output string in reversing order ccp Shell Programming and Scripting 3 11-19-2005 11:05 AM
sort a file in reverse order frustrated1 Shell Programming and Scripting 11 09-21-2005 04:41 PM
look in file, seperate letters, put in order... chekeitout UNIX for Advanced & Expert Users 3 11-05-2004 05:00 PM
Sorting filenames by order in another file samudimu UNIX for Advanced & Expert Users 4 05-24-2002 01:03 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-30-2002
MBGPS MBGPS is offline
Registered User
  
 

Join Date: Jun 2002
Location: London Uk
Posts: 14
Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file.

For example I have a file that says
a
b
c
d

I want to change this to be
d
c
b
a

Im trying to use sed to this by reading the file and then inserting each line at the top

#!/usr/bin/ksh

PATCHFILE=patch_order
REVERSE=reverse_
REVERSEPATCHFILE=$REVERSE$PATCHFILE
TMP=.TMP

rm $REVERSEPATCHFILE$TMP

echo got here
while read PATCHNAME; do

sed -e "1i\\
$PATCHNAME" >$REVERSEPATCHFILE$TMP

#mv $REVERSEPATCHFILE$TMP $REVERSEPATCHFILE

done <$PATCHFILE

The problem is it just puts the lines in exactly the same order. Am i missing something?
 

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 04:56 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