Visit Our UNIX and Linux User Community


Combining data from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combining data from file
# 1  
Old 04-16-2012
Combining data from file

Hi All,

I have file f1 contains :

f1;
Code:
Server Name1
te-1212hdsfhf-12kll-56565
Server Name2
jd-1212hdsfhf-12kll-5677
Server Name3
ty-1212hdsfhf-12kll-444
....

I have to produce f2 with the output:

f2:
Code:
Server1 te-1212hdsfhf-12kll-56565
Server2 jd-1212hdsfhf-12kll-5677
Server3 ty-1212hdsfhf-12kll-444

Can we write one liner for this ?

Thanks
'Krsna!

Last edited by Franklin52; 04-16-2012 at 06:33 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 04-16-2012
Code:
$ nawk '{a=$1;a=a""substr($2,length($2)-1,length($1));getline;printf("%s %s\n",a,$0)}' input.txt
Servere1 te-1212hdsfhf-12kll-56565
Servere2 jd-1212hdsfhf-12kll-5677
Servere3 ty-1212hdsfhf-12kll-444

# 3  
Old 04-16-2012
Code:
awk 'NR%2{gsub(/[A-Za-z]/,z,$2);$1=$1 $2;printf $1 FS;next}1' file

# 4  
Old 04-16-2012
Code:
awk '{$1="Server" (++i);getline $2}1' infile

Code:
awk '{$1=$1 (++i);getline $2}1' infile

# 5  
Old 04-16-2012
Combining data from file

Thanks All,

Hi Scurit,

Your code is giving output like :

Code:
Server te-1212hdsfhf-12kll-56565
Server jd-1212hdsfhf-12kll-5677
Server ty-1212hdsfhf-12kll-444

Server 1,2,3 is missing. Server name can be anything?

Thanks
Krsna

Last edited by Scrutinizer; 04-16-2012 at 09:28 AM..
# 6  
Old 04-16-2012
Quote:
Originally Posted by itkamaraj
Code:
$ nawk '{a=$1;a=a""substr($2,length($2)-1,length($1));getline;printf("%s %s\n",a,$0)}' input.txt
Servere1 te-1212hdsfhf-12kll-56565
Servere2 jd-1212hdsfhf-12kll-5677
Servere3 ty-1212hdsfhf-12kll-444

use awk, if you dont have nawk

Last edited by Scrutinizer; 04-16-2012 at 09:29 AM.. Reason: code tags
# 7  
Old 04-16-2012
Combining data from file

Hi Itkamaraj,

Thanks , If you do not mind can you please explain me this one liner how diff parts works..
Code:
nawk '{a=$1;a=a""substr($2,length($2)-1,length($1));getline;printf("%s %s\n",a,$0)}' input.txt


Thanks
Krsna

Last edited by Franklin52; 04-16-2012 at 07:34 AM.. Reason: Please use code tags for code and data samples, thank you

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining certain columns of multiple files into one file

Hello Unix gurus, I have a large number of files (say X) each containing two columns of data and the same number of rows. I would like to combine these files to create a unique merged file containing X columns corresponding to the second column of each file (with a bonus of having the first... (3 Replies)
Discussion started by: ksennin
3 Replies

2. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

3. Shell Programming and Scripting

Combining chunks of data

Hi there! Need help on some issue, I have data like this: 123 456 789 012 i need it to be like this: 123789 456012 Anyone has any idea how to do this? Thanks! Regards, Ken How to use code tags (8 Replies)
Discussion started by: kennethtls
8 Replies

4. Shell Programming and Scripting

Combining 2 lines in a file into 1 line

Hi all, I have a file with lot of lines with repeating pattern. ( TABLE_NAME line followed by Total line). I would like combine these two lines into one line seperated by cama and create a new file. Is there a simple way to do this. Current Format ( just a sample 4 lines ) TABLE_NAME:... (10 Replies)
Discussion started by: MKNENI
10 Replies

5. UNIX for Dummies Questions & Answers

Help with combining the ls and 'file' commands

I have a directory of 3000 files without extensions (Solaris 5.10). I would like to iterate the file names through the 'file' command and output their mime types (most are pdf or jpg, but a very few might be psd or swf which show simply as 'data') So, I would like the output of the 'ls'... (2 Replies)
Discussion started by: pwallace
2 Replies

6. Shell Programming and Scripting

Combining header and data and send email without usage of temp file

Dear All- My requirement is as below- Header file $ cat HEADER.txt RequestId: RequestDate: Data file $ cat DATAVAL.txt 1001|2009-03-01 I need to send the combined data below as email body via mailx command ------------------ RequestId:1001 RequestDate:2009-03-01 I would like... (4 Replies)
Discussion started by: sureshg_sampat
4 Replies

7. UNIX for Dummies Questions & Answers

Combining lines of files to new file

Hi everybody. I have a number of files that i would like to combine. however not concatenating, but rather extract lines from the files. Example: File1 ------ File2 ------File3 ... line11 ---- line21 ---- line31 ... line12 ---- line22 ---- line32 ... line13 ... (3 Replies)
Discussion started by: kabbo
3 Replies

8. Shell Programming and Scripting

Compare two csv files by two colums and create third file combining data from them.

I've got two large csv text table files with different number of columns each. I have to compare them based on first two columns and create resulting file that would in case of matched first two columns include all values from first one and all values (except first two colums) from second one. I... (5 Replies)
Discussion started by: agb2008
5 Replies

9. Shell Programming and Scripting

combining 2 files with more than one match in second file

Hello, I am attempting to combine two files where the second file can have more than one match with the lookup field (node) in the first file, onto one line of the output file. Also alerting if a lookup was not found in file2 =-=-=-=-=-=-= Example of file1 node,type =-=-=-=-=-=-= bob,232... (5 Replies)
Discussion started by: johnes42
5 Replies

10. UNIX for Dummies Questions & Answers

Combining information from a comma delimited file

I have a comma delimited file which also contains commas in the text. I was wondering how I can combine one whole column of that file with another file. In essence I'm trying to do an excel vlookup in UNIX to return the information from one column in the comma delimited file(containing text commas... (1 Reply)
Discussion started by: vzismann
1 Replies

Featured Tech Videos