The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with command line sopel39 Shell Programming and Scripting 0 11-09-2007 06:27 AM
Problem parsing line in file rlwilli Shell Programming and Scripting 2 09-02-2006 12:15 PM
$line command problem victorin Shell Programming and Scripting 3 07-21-2006 11:26 AM
Line wrapping problem when using awk placroix1 Shell Programming and Scripting 1 05-10-2005 12:44 PM
Sed new line problem Cordially UNIX for Dummies Questions & Answers 1 03-03-2004 11:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2006
mskcc mskcc is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 37
problem with new line

Hi Masters,

Here is the code someone posted days ago, but it didn't work well because it did't omit the newline character when $2 conbines. Can someone help me out?

awk '{if($1==prev) printf(" /// "$2); else {printf("\n"$1" " $2);prev=$1}}'

Basically, this code is trying to remove the redundent line in a two column spreadsheet file based on the field one, but merge field 2 if field one is redundent.

Thanks in advance.
  #2 (permalink)  
Old 04-04-2006
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
Need the sample text again please.
I think your thread was removed in violation of Rule Number 6.
  #3 (permalink)  
Old 04-04-2006
mskcc mskcc is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 37
Thanks! You are right. So I am fraid of violating rules again. But the basic idea is,

H82421 RDH11
H82421 DKFZP564M1462
H82435 BAGE4
H82435 MLL3
H82527 C20orf17
H82532 -
H82706 ID2
H82801 -
H82812 TNRC6B
H82872 UACA

What I need,

H82421 RDH11 /// DKFZP564M1462
H82435 BAGE4 /// MLL3
H82527 C20orf17
H82532 -
H82706 ID2
H82801 -
H82812 TNRC6B
H82872 UACA

Your code gave the line break in between $2,
H82421 RDH11^M /// DKFZP564M1462
H82435 BAGE4^M /// MLL3
H82527 C20orf17
H82532 -
H82706 ID2
H82801 -
H82812 TNRC6B
H82872 UACA

I could use some text editor to remove line breaks, but thought the complete code could be helpful for other people too. In addition, if the redundent lines are not sorted, what code should be? Thanks so much.
  #4 (permalink)  
Old 04-04-2006
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
Are you by any chance viewing the output file in DOS/Windows?
"^M" normally appears when you do so..as these OSes do not recognize new lines(UNIX) properly
  #5 (permalink)  
Old 04-04-2006
rajeeb_d rajeeb_d is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 37
Try this

awk 'BEGIN{x="";i=0} NR == 1 {x=$1;y=$0} NR > 1 && x == $1 {printf("%s /// %s\n",y,$2);i=NR+1} NR == i {x=$1;y=$0} NR > i && x != $1 {printf("%s\n",y);x=$1;y=$0} END {printf("%s\n",y);}'
  #6 (permalink)  
Old 04-04-2006
mskcc mskcc is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 37
Thank you all. Both of your code generated almost same output in terms of line breaks, second code didn't work with multiple redundent lines.

First output,
AA001897 SPTA1
AA001918 MI-ER1^M /// ER1^M /// KIAA1610^M /// DKFZp781G0451
AA001924 Cep63^M /// FLJ13386
AA001950 KIF13A
AA001952 -
AA001970 -
AA001976 -

Second output,
AA001897 SPTA1
AA001918 MI-ER1^M /// ER1
AA001918 MI-ER1^M /// KIAA1610
AA001918 MI-ER1^M /// DKFZp781G0451
AA001924 Cep63^M /// FLJ13386
AA001950 KIF13A
AA001952 -
AA001970 -
AA001976 -
AA002006 -

I just wonder if this is my os problem or not. I am using Mac OS X, and bash shell.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0