LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2011, 10:25 AM   #1
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Rep: Reputation: Disabled
how to combine same lines to one in a file


for example:
file:
1 2 3 4 A B C D
5 6 7 8 E F G H
9 10 11 12 A B C D
1 2 3 4 E F G H
5 6 7 8 I J K L
9 10 11 12 c f d h
3 4 1 2 11 12 5 6
9 10 5 6 7 8 2 3

I want to get the result like:

if the first 4 colomns is same, then combines the two lines to one, if not, no do.

1 2 3 4 A E B F C G D H
5 6 7 8 E I F J G K H L
9 10 11 12 A c B f C d D h
3 4 1 2 11 12 5 6
9 10 5 6 7 8 2 3
 
Old 11-06-2011, 12:02 PM   #2
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 184

Rep: Reputation: 25
is this your homework assignment ?
post what you have tried already...
 
0 members found this post helpful.
Old 11-06-2011, 01:40 PM   #3
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
I had no progress
 
0 members found this post helpful.
Old 11-06-2011, 02:09 PM   #4
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 184

Rep: Reputation: 25
i.e. you have not started yet ?
 
Old 11-06-2011, 04:51 PM   #5
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
I have started it, but I donot know how to do. I am learning AWK and SED for two weeks, but I can not find how to resolve this problem. I am a new linux learner
 
Old 11-06-2011, 05:47 PM   #6
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 184

Rep: Reputation: 25
nobody will give you a finished solution for your assignment here.
there's too many postings from new users with obvious homework questions for that.

make a real effort, and post your code / command that does not work, and people will give hints.
 
1 members found this post helpful.
Old 11-06-2011, 06:05 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by eagal View Post
I have started it, but I donot know how to do. I am learning AWK and SED for two weeks, but I can not find how to resolve this problem. I am a new linux learner
Have a look at http://www.gnu.org/s/gawk/manual/htm...Functions.html
and tell me if that makes a light-bulb light up :}



Cheers,
Tink
 
1 members found this post helpful.
Old 11-06-2011, 06:16 PM   #8
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Could you tell me whether the problem can be resolved by awk or sed? Thank you very much.
 
Old 11-06-2011, 06:50 PM   #9
scottro11
Member
 
Registered: Jun 2009
Location: NYC
Posts: 260

Rep: Reputation: 58
Have you tried

sed combine lines

in google. I see some answers on this forum.

We're not trying to be mean, but you really have to make a bit of effort yourself.
 
Old 11-06-2011, 06:57 PM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Yes both sed and awk could solve the problem.
 
Old 11-06-2011, 09:50 PM   #11
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
thanks a lot, guys. i will try in my best
 
Old 11-08-2011, 02:18 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Let us know how you got on?



Cheers,
Tink
 
Old 11-08-2011, 02:51 PM   #13
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks a lot for your concerning. My friend wrote a python script for me. It works well but the output is not suit to the next processing. So we are fixing it.
 
Old 11-08-2011, 03:45 PM   #14
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by eagal View Post
Thanks a lot for your concerning. My friend wrote a python script for me. It works well but the output is not suit to the next processing. So we are fixing it.
Now that won't help you much in learning sed or awk

Did he at least explain the concepts he's using in his python script
to you, so you could conceivably transfer the algorithm to other lingos?



Cheers,
Tink
 
Old 11-08-2011, 04:02 PM   #15
eagal
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thank you very much. He did not tell me about it. He is very busy. I am eagerly to finish my work. Work is the first, I will continue to learn awk and sed in the spare time. Thanks again.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy some lines in a file and delete these lines after gartura Linux - General 1 07-20-2010 09:55 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 07:18 PM
replace several lines in a file with other lines in another file if condition yara Linux - General 12 10-27-2009 04:46 PM
How would you combine files excluding the lines that are different? darcman Linux - Software 10 01-19-2009 08:23 PM
Substitute specific lines with lines from another file rahmathullakm Programming 4 01-10-2009 06:47 AM


All times are GMT -5. The time now is 06:18 AM.

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