Computing.Net > Forums > Unix > Trouble Merging lines

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Trouble Merging lines

Reply to Message Icon

Name: sting013
Date: August 19, 2003 at 12:37:47 Pacific
OS: sun
CPU/Ram: ?
Comment:

Hello all
I have been working on getting a flat file to merge two or three line into one. Below is part of a flat file I have.

Jan02 AF2
Jan02 UMSA2
Jan02 AF1
Jan05 AF2
Jan05 UMSA2
Jan08 AF2
Jan08 UMSA2
Jan10 AF2
Jan10 UMSA2
Jan11 AF2
Jan11 UMSA2
Jan11 AF1
Jan12 AF2
Jan12 UMSA2
Jan13 AF2
Jan13 UMSA2
Jan14 AF2
Jan14 UMSA2
Jan15 AF2
Jan15 UMSA2
Jan16 AF2
Jan16 UMSA2
Jan17 AF2
Jan17 UMSA2
Jan18 AF2
Jan18 UMSA2
Jan19 AF2
Jan19 UMSA2
Jan20 AF2
Jan20 UMSA2
Jan21 AF2
Jan21 UMSA2
Jan22 AF2
Jan22 UMSA2

The output I was tiring to get was
Jan02 AF2 UMSA2 AF1
Jan05 AF2 UMSA2
Jan08 AF2 UMSA2
and so on.

The problem I am running into is reading the file with a while loop and being able to compare the next line.
Any Help would be great.



Sponsored Link
Ads by Google

Response Number 1
Name: Frank
Date: August 19, 2003 at 23:31:17 Pacific
Reply:

Hi,

try
#!/bin/ksh
infile=input.txt
prev=" "


{ while read first rest
do
if [ "${prev}" = "${first}" ]
then
echo "${rest} \c"
else
prev=${first}
echo
echo "${prev} ${rest} \c"
fi
done } $infile


not tested but it should do it.

No RISK no fun
Frank


0

Response Number 2
Name: sting013
Date: August 20, 2003 at 05:52:14 Pacific
Reply:

Thank you so much works great


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Some tips in using IRIX nawk and grep -v problem



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Trouble Merging lines

trouble merging two files with awk www.computing.net/answers/unix/trouble-merging-two-files-with-awk/7937.html

Merging 2 lines www.computing.net/answers/unix/merging-2-lines/5084.html

Merge multiple files line by line www.computing.net/answers/unix/merge-multiple-files-line-by-line/8357.html