LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-04-2004, 10:01 AM   #1
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Rep: Reputation: 15
Post textfile editing


Hi all,
i have a little problem handling a textfile looking like this:



Word1 eagrtaerg erage rghegegretg
#greqrge rgergtegtwretg
rthgrethreth
regtrwthgrwthrht

Word1 rstgwrtgwrhtrwhtrh whgrthgwr
#gegtrewtrghwrethg
trgwwrthgrthg
wretghwrhtwr

Word1 rstgwrtgwrhtrwhtrh whgrthgwr
#gegtrewtrghwrethg
trgwwrthgrthg
wretghwrhtwr


The Textblocks are all seperated with a blank line how can i get the textblocks sorted alphabeticaly depending on the first word in the first line of a textblock.
Sorting the Textblocks is the goal i tried serachiong for some ready to use awk lines but awk is a little too difficult for a beginner like me....


Can u please help me ???

blubbfish
 
Old 10-04-2004, 01:38 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
This smacks of homework :)


Are you saying you want to sort by Word1?
That's a silly thing to do if the word is always
the same ;}



Cheers,
Tink
 
Old 10-04-2004, 02:05 PM   #3
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Original Poster
Rep: Reputation: 15
no Word1 is just the place of the first word word one could be "Marry" in the first Textblock and "Jim" in the next one... I have to order the textblocks seperated by a empty line alphabetically depending on the first wird of the textblock .....
 
Old 10-06-2004, 01:18 PM   #4
markham82
LQ Newbie
 
Registered: Oct 2004
Location: Rochester, NY, USA
Distribution: Red Hat 7, 9, Fedora Core 2, Windows 2000/XP
Posts: 27

Rep: Reputation: 15
I know AWK fairly well and might be able to help you out... but I don't understrand, where do you get "Marry" and "Jim" from?
 
Old 10-06-2004, 01:30 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
He just offered them as replacements for the
original "Word1" that he had in each paragraph.


Cheers,
Tink
 
Old 10-06-2004, 02:08 PM   #6
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Original Poster
Rep: Reputation: 15
yes that is the point the first word can be any word .... you can take what you want but i have to sort the textparts which could be more then one line and which are seperated by an empty line by the first word in the first line of each textpart
 
Old 10-06-2004, 03:00 PM   #7
TheMusicGuy
Member
 
Registered: Mar 2004
Distribution: Ubuntu 8.04
Posts: 127

Rep: Reputation: 15
Just gonna throw this in there...

What word processor are you using?
 
Old 10-07-2004, 03:57 AM   #8
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Original Poster
Rep: Reputation: 15
Word Prozessor ??? ???
the textfile i get is some kind of configfile made with command line vi and the sort mechanism is because the file is huge! And in order to get a better overview i shall sort this file by the first word in each textpart
 
Old 10-08-2004, 09:32 AM   #9
gunter
Member
 
Registered: Jan 2003
Distribution: Gentoo
Posts: 65

Rep: Reputation: 15
This would be easier for someone to figure out if you copy and paste part of the file here. Perhaps
Code:
head yourfile > sample
Then post sample here.

In the meantime, I created a file called test and it looks like the following:
Code:
gunter@anduin $ cat test

Steve eagrtaerg erage rghegegretg 
#greqrge rgergtegtwretg
rthgrethreth
regtrwthgrwthrht

Ralph rstgwrtgwrhtrwhtrh whgrthgwr 
#gegtrewtrghwrethg
trgwwrthgrthg
wretghwrhtw

gunter@anduin $
This can be sorted using the following line:
Code:
cat test | sed 's/^$/^/' | tr '\n' '|' | tr '^' '\n' | sed 's/^|//' | sed '/^$/d' | sort | tr '|' '\n'
This may not work for you. It depends on the data in the file, hence the need for a sample.
 
Old 10-20-2004, 02:00 AM   #10
blubbfish
LQ Newbie
 
Registered: Feb 2004
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks Gunter this is exactly what i was looking for ;-) nice idea to first write the textparts in one file and then reconstrukt it after the sort this really was a way i never imagined to work ;-)

You really helped me

And btw. your example file is very similar to mine ;-)


Greetings my Master i'll pray for yeah ...




Blubbfish
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoding of a textfile Anden008 Linux - Newbie 3 11-15-2005 02:07 PM
Textfile from linuxbox to winxpbox arnekasper Linux - Newbie 6 07-15-2005 05:58 AM
Help improving a textfile blubbfish Linux - Newbie 2 06-22-2004 08:02 AM
[c] adding header to textfile jb_li Programming 6 02-29-2004 01:17 AM
PDF to TextFile? Gerardoj Linux - Software 3 09-29-2003 05:00 PM


All times are GMT -5. The time now is 12:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration