Results 1 to 9 of 9
file a:
ffffff eee ccc r 12 ddd fff
file b:
k ccc bbbb zzz nnn eeeee aaaaaaaaa 3
how to combine a and b to c
shows like:
12 ...
- 05-12-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 5
how to sort these files?
file a:
ffffff eee ccc r 12 ddd fff
file b:
k ccc bbbb zzz nnn eeeee aaaaaaaaa 3
how to combine a and b to c
shows like:
12 3 aaaaaaaaa bbbb ccc ddd eee eeeee fff ffffff k nnn r zzz
Please Help
- 05-12-2010 #2
So there are a few steps here:
1) Split the lines in each file to put a single word on each line
2) Combine the two files
3) Sort the resulting file
4) Collapse all of the lines into a single line
Knowing this, do you know how to do any of these steps?DISTRO=Arch
Registered Linux User #388732
- 05-12-2010 #3Just Joined!
- Join Date
- May 2010
- Posts
- 5
- 05-13-2010 #4
Do you know anything about programming or scripting? If not, that may be a good place to start. I'm hesitant to just give you a script, because then you don't actually learn anything from this.
There's documentation available called man pages that can be accessed by "man COMMAND". This gives you a nice overview of various commands.
For step 1, you may want to look into "cut". Step 2 would be "cat", 3 is "sort", and 4 is actually pretty complicated. For step 4, we could use sed, which is actually a small programming language that lets you manipulate text.
If you look up the programs for 1 - 3 and give me some idea of how to do them, I'll give you the sed command.
Out of curiosity, what do you need this for?DISTRO=Arch
Registered Linux User #388732
- 05-13-2010 #5Just Joined!
- Join Date
- May 2010
- Posts
- 6
jason,
You can try with:
Hope it helps.Code:sed 's/\s/\n/g' filea fileb | sort -d | tr '\n' ' ' Explanation: sed 's/\s/\n/g' filea fileb -->Convert spaces (s) to end of line (\n) for both files, the output combines both files content. sort -d --> Sort in dictionary order with option "-d" tr '\n' ' ' --> Convert again the end of lines (\n) to spaces putting the column in a single line (transpose)
- 05-13-2010 #6Just Joined!
- Join Date
- May 2010
- Posts
- 5
- 05-13-2010 #7Just Joined!
- Join Date
- May 2010
- Posts
- 5
BTW, do I have to use For loop or IF statement here??
I am really confused by those syntax...@.@
- 05-13-2010 #8Just Joined!
- Join Date
- May 2010
- Posts
- 5
while read myline
do
echo $myline
done < ~/Desktop/a > ~/Desktop/c
while read mywords
do
echo $mywords
done < ~/Desktop/b > ~/Desktop/d
paste d c > ~/Desktop/e
while read line
do
echo $line
done < ~/Desktop/e > ~/Desktop/f
awk '{gsub(" ","\n"); print}' f > ~/Desktop/g
sort ~/Desktop/g > ~/Desktop/h
rm c
rm d
rm e
rm f
rm g
here is my code for the first 3 steps
figuring out last step
- 05-13-2010 #9Just Joined!
- Join Date
- May 2010
- Posts
- 6
jason
Did the solution I put above work for your problem?


Reply With Quote
