LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   textfile editing (https://www.linuxquestions.org/questions/linux-general-1/textfile-editing-238616/)

blubbfish 10-04-2004 10:01 AM

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

Tinkster 10-04-2004 01:38 PM

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

blubbfish 10-04-2004 02:05 PM

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 .....:confused:

markham82 10-06-2004 01:18 PM

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?

Tinkster 10-06-2004 01:30 PM

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


Cheers,
Tink

blubbfish 10-06-2004 02:08 PM

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 :confused:

TheMusicGuy 10-06-2004 03:00 PM

Just gonna throw this in there...

What word processor are you using?

blubbfish 10-07-2004 03:57 AM

Word Prozessor ??? :newbie: ???
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

gunter 10-08-2004 09:32 AM

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.

blubbfish 10-20-2004 02:00 AM

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 :D

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


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

:study:


Blubbfish


All times are GMT -5. The time now is 09:15 AM.