LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2009, 03:53 AM   #1
kadhan
Member
 
Registered: Dec 2004
Posts: 40

Rep: Reputation: 15
text rearrangement


I have a text file...
Code:
aaaaaa
bbbbbb
cccccc
1111111
aaabbb
aaaddd
ccceee
uuuuuu
2222222
fffffff
fffeee
666666
eewwww
uuuuuu
999999
I need the output file as
Code:
1111111
aaaaaa
1111111
bbbbbb
1111111
ccccc
1111111
aaabbb
2222222
aaaddd
2222222
ccceee
2222222
uuuuuu
2222222
fffffff
666666
fffeee
666666
eewwww
999999
uuuuuu
999999
I have no idea to do this.
Please help me to create this using any scripting language(sed/awk/perl)
.

Last edited by kadhan; 07-03-2009 at 01:08 AM.
 
Old 07-02-2009, 04:02 AM   #2
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
cat file | sort

wait a minute this don't do it' well it's a start;
 
Old 07-02-2009, 04:10 AM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Sounds like homework to me.

What languages are you familiar with, because I don't immediately see a simple command answer.
 
Old 07-02-2009, 04:17 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
first you should explain more clearly what is the criteria for rearrangement.
 
Old 07-02-2009, 05:13 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
print "
1111111
aaaaaa
1111111
bbbbbb
c1111111
ccccc
1111111
aaabbb
2222222
aaaddd
2222222
ccceee
2222222
uuuuuu
2222222
fffffff
666666
fffeee
666666
eewwww
999999
uuuuuu
999999";
 
Old 07-02-2009, 06:11 AM   #6
kadhan
Member
 
Registered: Dec 2004
Posts: 40

Original Poster
Rep: Reputation: 15
thanks bigearsbilly for your support....
 
Old 07-02-2009, 08:20 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by kadhan View Post
thanks bigearsbilly for your support....
So far you have failed to formulate the needed algorithm - though ghostdog74 has already suggested to so.
 
Old 07-02-2009, 09:32 AM   #8
nowonmai
Member
 
Registered: Jun 2003
Posts: 481

Rep: Reputation: 48
Quote:
Originally Posted by billymayday View Post
Sounds like homework to me.
yup
 
Old 07-02-2009, 09:49 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
Originally Posted by kadhan View Post
thanks bigearsbilly for your support....
I put as much effort in to my answer as you put in the original post.

we give support but you must reciprocate.
at least put some effort in; you have not even explained the problem!


we can't be expected to sit and work out what is supposed to be happening.
plus it's almost definitely homework by the looks of it.

we generally help those who help themselves


if you explain better, and it's homework we will give pointers but
not solutions!

ok dude?
 
Old 07-03-2009, 01:12 AM   #10
kadhan
Member
 
Registered: Dec 2004
Posts: 40

Original Poster
Rep: Reputation: 15
Ok I will explain my question.

First i need to search the first occurance of digit (111111 or 222222 like that...) and insert this same line in each line above the searched line. After this insertion search next occurance of digit and that line.


regards,
KaD.
 
Old 07-03-2009, 05:25 AM   #11
nowonmai
Member
 
Registered: Jun 2003
Posts: 481

Rep: Reputation: 48
To be fair, you're still not really putting much effort in here...
What languages do you know?
What have you tried so far?
 
Old 07-03-2009, 11:34 AM   #12
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Sort of really painful if we don't really understand what you want to do
By what you meant, doesn't it sound like it will have an endless or irrational output?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
Steps needed to convert multiple text files into one master text file jamtech Programming 5 10-07-2007 11:24 PM
software raid - device rearrangement after reboot when drives are disconnected rtspitz Linux - Hardware 5 07-08-2007 08:00 PM
in Pascal: how to exec a program, discard text output or send to text file Valkyrie_of_valhalla Programming 6 05-02-2007 09:50 AM
Partition rearrangement & dual booting Ubuntu/XP via GRUB VoidRoamer Linux - Hardware 9 04-29-2007 08:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration