Text manipulation help

C

Cristian

Guest
Hi,

I'm trying to sort out a text document which looks like this:

Code:
Alvaro Costa    Daldit Kaur Sings    Brian G Heward
Desmond Ogilvie    John Der    William Gherasim
Lance Mackey    Donald Kopplin    Robert Mckinlay
Jahir Hussain Mohamed    Jack Benaim    Abraham Weiss

Want it to sort to look like this:

Code:
Alvaro
Costa
Daldit
Kaur
Sings
Brian
G
Heward
 


A very simple method is to just open your file in gedit and use CTRL-H to find and replace the spaces with a "new line". You have to run it twice: one time to replace the set of 4 spaces, and run it again to replace the single spaces. Use actual spaces in the Search for: box, and use "\n" (without quotes) in the Replace with: box. Then click the Replace All button to complete the task.

Gedit remembers your previous "Search for" category, so the spaces could be confusing. If you search for the 4 spaces first, then when you run it a second time you may need to hit space once, then hit the delete key so that the remaining 3 spaces are actually removed.

Other text editors may work similarly. I only tested gedit and it worked great. You might even like the output of just removing the 4 spaces since it puts each name individually on its own line.

Good luck!
 
Hi,

I'm trying to sort out a text document which looks like this:

Code:
Alvaro Costa    Daldit Kaur Sings    Brian G Heward
Desmond Ogilvie    John Der    William Gherasim
Lance Mackey    Donald Kopplin    Robert Mckinlay
Jahir Hussain Mohamed    Jack Benaim    Abraham Weiss

Want it to sort to look like this:

Code:
Alvaro
Costa
Daldit
Kaur
Sings
Brian
G
Heward
There are many ways of doing this on the command line. A simple Google search has brought up many solutions quicker than you could have written your original question.

Look at sed, awk, tr, perl, and possibly other commands, or combination of commands to find your solution. As with most jobs in Linux, TIMTOWTDI (There Is More Than One Way To Do It!) ;^)

I have to assume this is a homework assignment, so I will not do your work for you. If this is, think about what you learned in the class where you received the assignment, and previous classes. Your instructor has probably given you all the clues you need to complete the assignment on your own without any help.
 
Looks like space and tab delimited??? Like rstanley said, sed and tr will be key. Use | (pipes) as well
 
Kinda sorted out. Did like this:
Made a "exe" file with:

awk '{print $1}' < file > x1
awk '{print $2}' < file > x2
awk '{print $3}' < file > x3
awk '{print $4}' < file > x4
awk '{print $5}' < file > x5
awk '{print $6}' < file > x6
awk '{print $7}' < file > x7
awk '{print $8}' < file > x8

After:

./do file
cat x* >> newfile
cat newfile | sort | uniq >> newfile2

tr '[A-Z]' '[a-z]' < newfile2 > newfile3

cat newfile3 | sort | uniq >> newfile4

And there I have it. I know its kinda messy and complicated but it suits my needs.
 

Members online


Top