Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting lines from 8 files and combining thm into just 1 file 2

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi all,

This may be an easy thing I am missing. But is there a way I can extract lines of text out of 8 files and combine them into just 1 file. I have tried looking at using 'sed' for this but not sure how to do it. Currently using AIX 4.3.3 ML9.

Thanks.


( "To become Wise, first you must ask Questions")
 
could you post an example of what are you trying to reach? I mean, with your question the answer could be a "cat file1 file2 > final_file" but I'm pretty sure this is not what you want.

Anyway, awk could help you ore than sed (I guess).

Cheers.
 
Okay. I have now managed to create 1 output file from an Informix database. Here is some example data:

07963213829;2616007;04;MPRC - WIP ;2004-01-15 17:01;Y;A/P SE0086 FLEXI CONN
; ; ; 2;351884002137232 ; ;;1; ;1; ; ; ; ;1; ; ;B C/VR

07963213829;2616007;04;MPRC - WIP ;2004-01-15 17:01;Y;REPLACED FLEXI/OUTER LENS/ BATTERY
; ; ; 2;351884002137232 ; ;;1; ;1; ; ; ; ;1; ; ;B C/VR

07963213829;2616007;04;MPRC - WIP ;2004-01-15 17:01;Y;TESTED TO SPEC
; ; ; 2;351884002137232 ; ;;1; ;1; ; ; ; ;1; ; ;B C/VR


For example the second field (;) will be an identifier number. For example: 2616007.
In the 5th field is a comment. Example: TESTED TO SPEC.

As you will notice I have duplicated lines with the same identifier number but with different comments in the 5th field.

What I need to is to identify the second field number. And from that insert any other 5th fields onto the same line and create 1 line with all the fields and a combined text of the 5th field from the duplicated lines.

For example I am after this from it:

07963213829;2616007;04;MPRC - WIP ;2004-01-15 17:01;Y;A/P SE0086 FLEXI CONN REPLACED FLEXI/OUTER LENS/ BATTERY TESTED TO SPEC ; ; ; 2;351884002137232 ; ;;1; ;1; ; ; ; ;1; ; ;B C/VR


I hope that makes sense?

Thanks again.

( "To become Wise, first you must ask Questions")
 
A starting point (typed, not tested):
nawk '
BEGIN{FS=OFS=";"}
k!=$2{if(k)print x;k=$2;x=$0;next}
{c=$5;$0=x;$5=$5" "c;x=$0}
END{print x}
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV. Tried your code. This is what the output ended as:

07963213829;2616007;04;MPRC - WIP ;2004-01-15 17:01 2004-01-15 17:01 2004-01-15 17:01;Y;A/P SE0086
FLEXI CONN ; ; ; 2;351884002137232 ; ;;1;
;1; ; ; ; ;1; ; ;B C/VR

As you can see it didn't pull in the other 2 comments as explained. I Even substituted your nawk ' with a gawk ' in the script and the same output came back. Any other ideas? Also note that this original file will have more data with different 2nd field numbers which also I need to bring into 1 line each.


( "To become Wise, first you must ask Questions")
 
As you can see it didn't pull in the other 2 comments as explained.

you posted "the 5th field", but actually es the 7th. So PHV's script is doing it right. Replace $5 with $7.

note that this original file will have more data with different 2nd field numbers which also I need to bring into 1 line each

post an example!!!
 
Chacalinc. Damn, I eally must look more carefully. Yep Sorry PHV that now works with the correct field postion (7).

I first will check if PHV's donation script will do the job for the other lines. If not I will post some example data.

Thanks guys.


( "To become Wise, first you must ask Questions")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top