to get two almost identical rows into one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to get two almost identical rows into one
# 1  
Old 08-17-2009
Question to get two almost identical rows into one

Hi All,
I am having hard time in getting two almost identical rows into one, I know how to do if starting word is unique, anyhow this is my problem

Input File:
issue1 5167
dum 1 1 kkk 7888
dum 2 1 ffff 7888
dum 2 2 llll 7888
dum 3 1 eee 7888
issue2 7667
dum 2 1 jjjj 8999
dum 2 2 jjjj 8999
dum 3 pppp 8999

Output should be:
issue1 5167 1 kkk 2 ffff 2 llll 3 eee
issue2 7667 2 jjjj 3 pppp


Can someone give me a idea, of how to proceed with this, would be grately helpful if anyone can put all those ideas into writing...

Thanks,
Ricky
# 2  
Old 08-17-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.
  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote


Code:
awk '{if(/issue/){if(NR>1){printf "\n%s",$0}else{printf}}else{printf " %s %s",$2,$4}}' file

# 3  
Old 08-17-2009
Thanks alot danmero!!!!!
# 4  
Old 08-17-2009
Code:
while(<DATA>){
	chomp;
	if(/^issue/){
		if($.==1){
			print $_;
		}
		else{
			print "\n$_";
		}
	}
	else{
		my @tmp=split;
		print join " ",(" ",@tmp[1,3]);
	}
}
__DATA__
issue1 5167
dum 1 1 kkk 7888
dum 2 1 ffff 7888
dum 2 2 llll 7888
dum 3 1 eee 7888
issue2 7667
dum 2 1 jjjj 8999
dum 2 2 jjjj 8999
dum 3 pppp 8999

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print text between 2 identical strings

hey, i m having a hard time trying to print only the first occurrence between 2 idenicale strings. for the following output: please help me im a noob please im a noob help me noob please help me im a noob please im a noob help me noob (3 Replies)
Discussion started by: boaz733
3 Replies

2. Ubuntu

reinstall identical system?

I have my Ubuntu system nicely tailored to my needs, with specific software installed, and other things removed. I'd like to build a new PC, and have the identical software configuration on it. Is there some easy way to export the list of installed software to a file? Then have the new machine... (3 Replies)
Discussion started by: lupin..the..3rd
3 Replies

3. UNIX for Dummies Questions & Answers

more than 10 identical lines

I have a file that looks like this 10 user1s, 5 user2s and 10 users3. 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.2 user2 10.10.1.2 user2 10.10.1.2 user2... (7 Replies)
Discussion started by: lawsongeek
7 Replies

4. Solaris

Mirroring using non-identical disks

I've been testing mirroring root partitions for the past few days within a virtual environment and on an old ML350. However, the live system that this is practice for has two disks, and they're non-identical. I've done a bit of searching through the forum and see that a lot of people recommend... (2 Replies)
Discussion started by: lm69a
2 Replies

5. Shell Programming and Scripting

Removing identical words in column

I have a file that needs to be cleaned up. Here is the file: 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: Project John Gary Sean Project2 (7 Replies)
Discussion started by: leepet01
7 Replies

6. Shell Programming and Scripting

Ignore identical lines

Hello Experts, I have two files called "old" and "new". My old file contains 10 lines and my new file contains 10 + "n" lines. The first field in both these files contain ID. I sort these two files on ID. I am interested in only the lines that are in the new file and not in old. I tried... (4 Replies)
Discussion started by: forumthreads
4 Replies

7. UNIX for Dummies Questions & Answers

du -s -k differences between two identical directories

I tarred a directory from a linux server to a solaris server. When I do a du -s -k on the directory, I get almost 150k difference in the file sizes. If I do a ls | wc -l, it is the same. If I look at the size of the individual files, it is the same. I did an ls on the 2 directories and... (6 Replies)
Discussion started by: csgonan
6 Replies

8. Shell Programming and Scripting

replace 2 identical strings on different lines

I am looking to replace two or more strings on different lines using sed, but not with the same variable. IE # cat xxx.file <abc> abc def ghi abc def ghi abc def ghi currently I can only change each line with the same pattern: # sed -e '/<abc>/!s/abc\(.*\)/jkl mno/' xxx.file abc jkl mno... (3 Replies)
Discussion started by: prkfriryce
3 Replies

9. Shell Programming and Scripting

list only identical filename

Hi Friends, We have four filenames with first few digits are identical.From those files, i need to pick up 2 files based on my parameter. The following example will give more information to understand my question. Files in the directory: small_customer_aa.csv small_customer_ab.csv... (6 Replies)
Discussion started by: HAA
6 Replies

10. UNIX for Dummies Questions & Answers

How to check the files are Identical or not?

Hi, I am taking backup in every hr and every day, I want to programmatically check my backup files are identical with original files. Any methods are available in Unix scripts? Any idea.? I don't want to download both and compare, I looking for idea to develop a script to read both files and... (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question