How to concatene files and put each line of files on a specific position ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to concatene files and put each line of files on a specific position ?
# 1  
Old 07-13-2012
How to concatene files and put each line of files on a specific position ?

Hi,

I have some files that i want to concatene and put each of lines of this files on a specific position :

File1
Code:
AAAAAAA
BBBBBBB
CCCCCCC

File2
Code:
DDDDDDD
EEEEEEE
FFFFFFF

File3
Code:
GGGGGG
HHHHHH
IIIIII

New file
Code:
AAAAAAA         DDDDDDD  GGGGGG
BBBBBBB           EEEEEEE     HHHHHH
CCCCCCC           FFFFFFF       IIIIII

DDDDDDD - EEEEEEE - FFFFFFFF (in position 40)
GGGGGG - HHHHHH - IIIIII (in position 60)


I try to make the operation with paste, awk, sed without result.

What is the best way to make this.
I'm newbie in shell script.

Thanks in advance.

Last edited by Scrutinizer; 07-13-2012 at 07:48 AM.. Reason: code tags - Formatting
# 2  
Old 07-13-2012
Quote:
Originally Posted by apippo70
New file
AAAAAAA DDDDDDD GGGGGG
BBBBBBB EEEEEEE HHHHHH
CCCCCCC FFFFFFF IIIIII

DDDDDDD - EEEEEEE - FFFFFFFF (in position 40)
GGGGGG - HHHHHH - IIIIII (in position 60)
How does one arrive at lines in red?
# 3  
Old 07-13-2012
Just perform a matrix transposition
Code:
[root@node3 ~]# cat file1
AAAAAAA
BBBBBBB
CCCCCCC
[root@node3 ~]# cat file2
DDDDDDD
EEEEEEE
FFFFFFF
[root@node3 ~]# cat file3
GGGGGG
HHHHHH
IIIIII
[root@node3 ~]# cat transpose.sh 
#!/bin/bash 
# 
# transpose 
 
transpose() 
{ 
  awk ' 
      { 
              if (max_nf<NF) 
                    max_nf=NF 
              max_nr=NR 
              for (x=1; x<=NF; ++x) 
                     matrix[x, NR]=$x 
      } 
 
  END { 
              for (x=1; x<=max_nf; ++x) { 
                   for (y=1; y<=max_nr; ++y) 
                        printf("%s ", matrix[x, y]) 
                   printf("\n") 
              } 
      }'  ${1} 
} 
 
transpose ${1} 
[root@node3 ~]# xargs -n 3 < <(cat file*) | bash transpose.sh
AAAAAAA DDDDDDD GGGGGG 
BBBBBBB EEEEEEE HHHHHH 
CCCCCCC FFFFFFF IIIIII

# 4  
Old 07-13-2012
Alternatively, try:
Code:
paste File[123]

To put col2 in pos40 and col3 in pos 60, try:
Code:
paste File[123] | awk '{printf "%-39s%-20s%-20s\n",$1,$2,$3}'

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 07-13-2012
Thank for the replies. I have just a problem when in the files i have one or more spaces. The result are not in the right position.

Thank.
# 6  
Old 07-13-2012
Choose a temporary delimiter that does not exist within the file..
Code:
paste -d '~' File[123] | awk -F '~' '{printf "%-39s%-20s%-20s\n",$1,$2,$3}'

This User Gave Thanks to Ygor For This Post:
# 7  
Old 07-13-2012
Is there the possibility to ignore the delete space just for 1 file to the following command ?

Code:
paste -d '~' File[123] | awk -F '~' '{printf "%-39s%-20s%-20s\n",$1,$2,$3}'


Last edited by apippo70; 07-13-2012 at 11:58 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Remove line break at specific position

Hi, I need to remove line breaks from a file, but only the ones at specific position. Input file: this is ok this line is divided at posit ion 30. The same as this one, also position 30 the rest of lines are ok with different lengths The longest ones are always s plitted at same... (15 Replies)
Discussion started by: qranumo
15 Replies

3. Shell Programming and Scripting

Need help on find and replacement on specific line and position

I have a file with 100 lines. On 50 th line , from position 5 to rest of the data , I need to change the occurrence of A to B and Occurrence of M to N. Input file : Line1 Line2 Line3 -- -- 12345ABCDEFM --- -- Line 100 Output Line1 Line2 (40 Replies)
Discussion started by: Rajesh_us
40 Replies

4. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

5. Shell Programming and Scripting

Put a # in start of a specific line of a file

Hello Guys Please let me know how to solve the below issue I have a file like below drop table R1416.ABC1 cascade constraints; drop table R1416.ABC2 cascade constraints; drop table R1416.ABC3 cascade constraints; drop table R1416.ABC4 cascade constraints; drop table R1416.ABC5... (7 Replies)
Discussion started by: Pratik4891
7 Replies

6. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

7. Shell Programming and Scripting

Search in specific position and print the whole line

I have two files abc.dat and sant.dat (Big file 60k rows) for every line's 1,4 of abc.dat need to seach if this is present on 28,4 of sant.dat every line. if its present the output needs to go to bde.dat Example: contents abc.dat aaaa bbbb cccc dddd contents sant.dat this is... (4 Replies)
Discussion started by: ssantoshss
4 Replies

8. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

9. Shell Programming and Scripting

check position of end of line for some specific lines

-------------------------------------------------------------------------------- Have to check in a file that the lines starting with 620 and 705 are ending at same posiotin. 82012345 62023232323 70523949558 62023255454 9999 In the above lines, i have to check the lines starting... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question