| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
If you are on *nx system (console):
cat a b |sort | sed -r 'N;/([^;]*).*\n\1/s|\n[^;]*||'
a b your files
cat concatenate the files
sort sort the combined file
sed:
N add next line
/([^;]*).*\n\1/ find repeating strings
s|\n[^;]*| delete second string
On 18/05/16 16:17, Ufuk YILDIRIM [email protected] [sed-users]
wrote:
> Hi all,
>
>
> First thing first, I am a total noob using sed. I can use it for simple
> tasks, but now I need to use it for a for-me-very-complex task. I have 4
> files of student data containing students responses to 4 different
> tests. Some students took two tests some only took one. I want to
> combine the results of a student who took 2 tests in a single line and
> get single file which has all the students and their responses in one
> file. Can I do it with sed? And, if yes, how do I do it?
>
>
> To clarify my question, here is two file version.
>
>
> fileA.txt
>
>
> ID111;a;a;a;a;a;a;a;a;a
> ID222222;a;a;a;a;a;a;a;a;a
> ID3333;a;a;a;a;a;a;a;a;a
>
>
> FileB.txt
>
>
> ID111;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID44;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID3333;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID555;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
>
>
>
>
> result.txt
> ID111;a;a;a;a;a;a;a;a;a;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID222222;a;a;a;a;a;a;a;a;a
> ID3333;a;a;a;a;a;a;a;a;a;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID44;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
> ID555;b;b;b;b;b;b;b;b;b;b;b;b;b;b;b
>
>
> Thank you very much in advance
>
>
> Ufuk YILDIRIM
>
>
> ------------------------------------
> Posted by: Ufuk YILDIRIM <[email protected]>
> ------------------------------------
>