|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with concatinating the data of 2 files
Hi All, I am trying to merge to 2 files 348.csv & 349.csv using join,awk commands but not getting proper output: Code:
cat 348.csv
Timestamp Server
348
02/04/2013 09:19 100
02/04/2013 09:20 250
02/04/2013 09:21 80Code:
cat 349.csv
Timestamp Server
349
02/04/2013 09:19 234
02/04/2013 09:20 13
02/04/2013 09:21 546Code:
Expected output
Timestamp Server
348 349
02/04/2013 09:19 100 234
02/04/2013 09:20 250 13
02/04/2013 09:21 80 546Code:
using below awk:
awk 'NR==FNR{i=NF<5?"__":$1$2$3$4;a[i]=$0;next} FNR==1{print}{i=NF<5?"__":$1$2$3$4}FNR>1&&i in a{print a[i],$NF}' 348.csv 349.csvCode:
using below join: join -a1 -a2 348.csv 349.csv Thanks, |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
This one relies upon your files having exactly synchronized, corresponding lines: Code:
awk 'NR==1 {print; getline < f1; next}
{getline ln < f1; print ln, $NF}
' f1="file1" file2
Timestamp Server
348 349
02/04/2013 09:19 100 234
02/04/2013 09:20 250 13
02/04/2013 09:21 80 546You may want to alter the OFS char to make the output prettier... |
| The Following User Says Thank You to RudiC For This Useful Post: | ||
ss_ss (02-06-2013) | ||
|
#4
|
|||
|
|||
|
Hi Pamu/Rudi, Thanks for your inputs, it worked well. But still facing some formatting issues i.e. both the numbers are coming under one server name only. Code:
Timestamp BRM Servers
348 349
02/05/2013 22:26 5 6
02/05/2013 22:36 5 6Need the numbers below their respective server names. Is there anyhting can be done? Thanks in advance!!!! |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
do mean like this..? Code:
$awk 'NR==FNR{A[NR]=$0;next}{ print A[FNR],$NF}' file1 file2
Timestamp Server Server
348 349
02/04/2013 09:19 100 234
02/04/2013 09:20 250 13
02/04/2013 09:21 80 546 |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
If you post two carefully composed input files, we can have a look onto the output formatting. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
The server id is not intentionally put to the far right, got messed up while posting.
In the input file also the nos would be below the server name and same is required in the output. Tried a lot posting a clean and formatted input output here but not able to do so, the server names are automatically shifting towards the right ![]() Thanks |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Concatinating the lines based on number of delimiters | bi.infa | Shell Programming and Scripting | 4 | 05-15-2012 01:02 PM |
| Problem when concatinating wildcard onto file location in bash script | Lears_Fool | Shell Programming and Scripting | 11 | 09-28-2010 04:06 PM |
| concatinating the string in each line of the file | mail2sant | Shell Programming and Scripting | 1 | 09-01-2009 04:59 PM |
| concatinating the array | mail2sant | Shell Programming and Scripting | 2 | 05-07-2009 05:12 AM |
| concatinating data | kingofprussia | UNIX for Dummies Questions & Answers | 1 | 05-06-2008 10:16 PM |
|
|