Removing identical words in column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing identical words in column
# 1  
Old 09-28-2010
Removing identical words in column

I have a file that needs to be cleaned up. Here is the file:
Code:
Project
Project John
Project Gary
Project Sean
Project2
Project2  Lisa
Project2  Tyler
Project2  Sam
Project3
Project3  Mike
Project3  Bran

I need the o/p to be:
Code:
Project
 John
 Gary
 Sean
Project2
 Lisa
 Tyler
 Sam
Project3
 Mike
 Bran

The file is tab delimited and I'm using /bin/sh in a Solaris env. Any help would be much appreciated.

Thanks!
# 2  
Old 09-28-2010
Code:
awk '{a[$1]++}a[$1}>1{$1=""}1' file

# 3  
Old 09-28-2010
Code:
$ ruby -ane 'print if $F.size<2; print "  #{$F[1]}\n" if $F.size>1 ' file
Project
  John
  Gary
  Sean
Project2
  Lisa
  Tyler
  Sam
Project3
  Mike
  Bran

# 4  
Old 09-28-2010
Quote:
Originally Posted by kurumi
Code:
$ ruby -ane 'print if $F.size<2; print "  #{$F[1]}\n" if $F.size>1 ' file
Project
  John
  Gary
  Sean
Project2
  Lisa
  Tyler
  Sam
Project3
  Mike
  Bran

I'm pretty sure OP won't find ruby on his Solaris machine Smilie
# 5  
Old 09-28-2010
Hey, Thanks for the help. I like the Ruby, and it worked on my Linux, but this script will need to run in the Solaris env.

I tried the awk statement:
Code:
awk '{a[$1]++}a[$1]>1{$1=""}1' filename

but received the syntax & bailing out error. Did I get it right on the command? I noticed you had a squigly bracket after the "a[$1}" I figured it was a typo and placed the ending square bracket "a[$1]".

Really appreciate the help!!!
# 6  
Old 09-28-2010
Try:
Code:
/usr/xpg4/bin/awk '{a[$1]++}a[$1]>1{$1=""}1' filename

# 7  
Old 09-28-2010
That Did It! Thank You!!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use regex on particular column (Removing comma from particular column)?

Hi, I have pipe separated file which contains some data having comma(,) in it. I want to remove the comma(,) only from particular column without changing data in other columns. Below is the sample data file, I want to remove the comma(,) only from 5th column. $ cat file1 ABC | DEF, HIJ|... (6 Replies)
Discussion started by: Prathmesh
6 Replies

2. Shell Programming and Scripting

removing the words with symbols in a file in unix

I have file like below Hi iam author <br>joseph</br> in france. I live in my home <br></br> but no food. I will play footbal <br></br> but i wont play cricket. I will read all the books <br>all fiction stories</br> i hate horror stories. I want output like below Hi iam author... (3 Replies)
Discussion started by: vinothsekark
3 Replies

3. Shell Programming and Scripting

Conditional removing of words from a line

Hi , I have a .csv file,from which I want to remove some data from each column as below. Source Data GT_12_AUDIT,SCHEDULED,NOZOMI2010/GT_12_AUDIT,CTSCAN/Zh_GT_6547887/GT_12_AUDIT,CTSCAN/Zh_GT_6547887... (3 Replies)
Discussion started by: gaur.deepti
3 Replies

4. UNIX for Dummies Questions & Answers

deleting words in list with more than 2 identical adjacent characters

Morning Guys & Gals, I am trying to figure out a way to remove lines from a file that have more than 2 identical characters in sequence.. So if for instance the list would look like ; the output would be ; I can't seem to get my head around perl (among many other... (7 Replies)
Discussion started by: TAPE
7 Replies

5. SuSE

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

6. Programming

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

7. Shell Programming and Scripting

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

8. Shell Programming and Scripting

finding and removing 2 identical consecutive words in a text

i want to write a shell script that correct a text file.for example if i have the input file: "john has has 2 apples anne has 3 oranges oranges" i want that the output file be like this: "john has 2 apples anne has 3 oranges" i've tried to read line by line from input text file into array... (11 Replies)
Discussion started by: cocostaec
11 Replies

9. Shell Programming and Scripting

removing 2 words from file.

Hi All, I have a text file with name of source files in that. source files ends with .mxml and .css. Now I want to remove the extensions of these source files. Currently I can do so by writing 2 sed commands, as there are files with just 2 different extensions. But I want to do it in one sed... (6 Replies)
Discussion started by: mkashif
6 Replies

10. Shell Programming and Scripting

Removing uppercase words from textfiles

I have the task of removing all uppercase words from csv files, mit 10000's lines. I think it shoud be possible with regex's, something like "s/{2,}//g" but I can't get it work with sed or Vi. It would also be possible to script in ksh, awk, perl or python. example this "this is a EXAMPLE... (5 Replies)
Discussion started by: frieling
5 Replies
Login or Register to Ask a Question