#1 26 Feb 2009 18:50

sam
Member
Registered: 26 Feb 2009
Posts: 1

a newbie request for some assisitance

I have recently started to use the Bash shell. I am reading about sed, awk and classic shell cookbook from O'reilly - especially about shell scripts for the manipulation of text files.

I want to create a shell script to re-arrange a large text file to create a new file in which line one from the original file is now followed by what was the final line in the original ; then follow this with line two from the original and then have the second last line from the original after that,  etc..

So, if there were ten lines in the text file,  the shell script would re-arrange their order into:

line 1
line 10
line 2
line 9
line 3
line 8

.....  and so on.

I should be able to work this out - and I apologise if this just sounds like lazy picking of brains - but i do lack  programming skills. This may be the wrong forum - but if anyone can point me in the right direction I would be very grateful.

sam

Last edited by sam (27 Feb 2009 23:12)


the volatility smile is not symmetrical

Offline

#2 28 Feb 2009 12:50

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 997
Website

Re: a newbie request for some assisitance

I would tackle this in 3 stages

1) step through the file and copy every odd line into file1 and every even line into file2

2) reverse the order of everything in file2

3) step through file1 and for each line, copy it and the corresponding line from file2 into file3

Offline

Board footer

Powered by FluxBB