column 1 line transitions part two!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting column 1 line transitions part two!
# 1  
Old 04-18-2008
column 1 line transitions part two!

I know I have already asked a similar question and the answer was awesome!...But it turns out I need something slightly different. I have a space delimited text file with thousands of lines, COLA.TXT that looks for example like this:
AA 123 456 789
AA 987 987 987
AA 987 988 888
AA 999 999 999
B 123 456 789
B 111 111 111
CCD 123 456 789
CCD 321 654 987
CCD
EE 11 11
EE
EE
EE 00 00 00
EE


Now I need to delete all the last lines of each "section" (sections are determined by the first field of each line)

sample output
AA 123 456 789
AA 987 987 987
AA 987 988 888
B 123 456 789
CCD 123 456 789
CCD 321 654 987
EE 11 11
EE
EE
EE 00 00 00
# 2  
Old 04-18-2008
Code:
for sec in $(cut -f 1 -d' ' buf | sort -u); do grep $sec buf | sed '$d'  ; done

# 3  
Old 04-18-2008
thx but....

thank you for that command....it works BUT....I forgot to mention that in my actual file there are sometimes sections "Y" and "YY" and "Y1" so I had to change grep $sec to grep "$sec "
does that sound about right?
# 4  
Old 04-18-2008
A solution with awk:

Code:
awk 'f!=$1{f=$1;s=$0;next}{print s;s=$0}' file

Regards
# 5  
Old 04-18-2008
Another one:

Code:
awk '__[$1]++{print _}{_=$0}' file

# 6  
Old 04-18-2008
Quote:
Originally Posted by radoulov
Another one:

Code:
awk '__[$1]++{print _}{_=$0}' file

Nice one Radoulov.Smilie
# 7  
Old 04-18-2008
Quote:
Originally Posted by Franklin52
Nice one Radoulov.Smilie
Thanks Smilie

(added for message too short ...)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete part of a column

I want to delete a part of the 4th column from the given file below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (2 Replies)
Discussion started by: my_Perl
2 Replies

2. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

3. Shell Programming and Scripting

Merge two files line by line and column by column

Hi All, I have two files having oracle query result. I want to merge to files line by line and also with column File1 23577|SYNC TYPE 23578|Order Number|ConnectionState 23585|Service State|Service NameFile2 23577|AR Alarm Sync 23578|A5499|9 23585|7|test_nov7Result... (18 Replies)
Discussion started by: Harshal22
18 Replies

4. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

5. Shell Programming and Scripting

awk to replace part of a column

dear all, I'm trying to use Awk to eliminate the last two characters from the first column in a file. This two characters are "-1" and I need to eliminate them from each row that I have in the files. The files have two columns and look like: ID_090-1 2 ID_3787-1 4 ID_0098-1 1 ID_12-1 4 I... (4 Replies)
Discussion started by: gabrysfe
4 Replies

6. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

7. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

8. Shell Programming and Scripting

Print part of line excluding one column

Hi, I have data which is having '|' as delimiter and have lobfilename/locations in the data. Ex: 1200|name1|lobfilename.0.600|abcd 1201|name2|lobfilename.600.1300|abcd My requirement is to print part of the line till the lobfilename and write to a different file and also print the... (4 Replies)
Discussion started by: newb
4 Replies

9. Shell Programming and Scripting

print line before column 1 transitions

I have a space delimited text file with thousands of lines, COLA.TXT that looks for example like this: AA 123 456 789 AA 987 987 987 AA 987 988 888 AA 999 999 999 B 123 456 789 B 111 111 111 CCD 123 456 789 CCD 321 654 987 CCD EE 11 11 EE EE EE 00 00 00 EE Anyway, I need a script... (2 Replies)
Discussion started by: ajp7701
2 Replies
Login or Register to Ask a Question