Script by row colum


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script by row colum
# 1  
Old 12-30-2014
Linux Script by row colum

Hi All,

how can output file1 to file2 by colum, e.g.


Code:
$cat file1

1
2
3

$cat file2

aaa bbb ccc
ddd eee fff
ggg hhh iii


then i need new file1

Code:
$ cat file2 > file1

and

Code:
$cat file1

1  aaa bbb ccc
2  ddd eee fff
3  ggg hhh iii


Last edited by Scrutinizer; 12-30-2014 at 07:09 PM.. Reason: CODE tags
# 2  
Old 12-30-2014
Use the paste command, for space separator use -d" " option:

Code:
$ paste -d" " file1 file2
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

To replace file1 just do:

Code:
$ paste -d" " file1 file2 > file3
$ mv file3 file1

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 12-31-2014
If it's just about line numbering...
Code:
nl -s '' -w3 -nln file2 > file1

This User Gave Thanks to ongoto For This Post:
# 4  
Old 12-31-2014
Code:
akshay@Aix:/tmp$ pr -m -t -s' ' file1 file2
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii

These 2 Users Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 12-31-2014
thanks XL and masters excelente very fine solution

happy hollydays
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vlookup using awk without exact match for two colum input

Source file 1 335 R1-snapfound 0098F RDFType:R1 R2-Dev R2-snapfound ,010C0 RemoteSymmetrixID:345 335 R1-snapfound 00990 RDFType:R1 R2-Dev R2-snapfound ,010C1 RemoteSymmetrixID:345 335 R1-snapfound 009C0 RDFType:R1 R2-Dev R2-snapfound ,009C1 RemoteSymmetrixID:345 335 R1-snapfound 009C1... (5 Replies)
Discussion started by: ranjancom2000
5 Replies

2. Shell Programming and Scripting

Colum number where value is >0

Hi All I want to findout coloum number where value is >0 from below string Can we do using awk or any command ? Thanks in advance ... (7 Replies)
Discussion started by: aaysa123
7 Replies

3. Shell Programming and Scripting

Sorting based on a particular colum

Hi, I want a flat file(pipe delimited) to be sorted based on 2nd column only. Below is input file to be sorted. AVERS|K50034|A|Y|N|N|Y|Y|Y|||N|N AVERS|K50035|A|Y|N|N|Y|Y|Y|||N|N... (11 Replies)
Discussion started by: Nikhath
11 Replies

4. Linux

Doubt on vmstat swpd colum

Dear Gurus, When i ran vmstat, i am getting swpd value,but si, and so beneath the swap is o, My doubt what is the difference between these values,i,e swpd and si and so OS is OEL 5.5 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r b swpd free buff cache... (2 Replies)
Discussion started by: dave234
2 Replies

5. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

6. UNIX for Dummies Questions & Answers

joining files with different rows and colum

Hi all, I have two files: file one (9 rows, 3 columns): A 1 x1 B 2 f1 C 3 f3 D 4 u5 E 5 l9 F 6 h6 G 7 g4 H 8 r4 I 9 s2 file two (4 rows, 1 column): A B (2 Replies)
Discussion started by: anjas
2 Replies

7. Shell Programming and Scripting

sed command to delete points in a certain colum

Dear Unix users, I have a (I think simple) question; I have a file (out.dat) like below, the file contains some line which include 'LOS' string. . LOS 46.5360 91.0220 200708.2515.4900. 5400 64 1100010 . . I would like to delete the points in 4th... (4 Replies)
Discussion started by: mgunduz
4 Replies

8. Shell Programming and Scripting

find lines have 2nd colum value greater than 40

i have a file a.txt 12345,20 34567,10 23123,50 123456,45 how to find lines which hav 2nd entry greater than 40 o/p 23123,50 123456,45 pls help to get o/p (5 Replies)
Discussion started by: devesh123
5 Replies

9. Shell Programming and Scripting

add multiple colum using awk

hi i need help in my script i have a file a.txt 3,4,5,13 6,7,8,45 9,0,1,67 i want to add 2nd and 3rd colum like o/p will be by adding all values of colum2(4+7+0) and colum 3(5+8+11) o/p: colum 2: 11 colum 3: 14 (6 Replies)
Discussion started by: anish19
6 Replies

10. Shell Programming and Scripting

sed or awk to convert text files with recurring headings to rows and colum

I have many text file reports generated by a Information Assurance tool that I need to get into a .CSV format or Excel tab delimited format. I want to use sed or awk to grab all the information in the sample text file below and create column headings:Risk ID, Risk Level, Category, Description, How... (5 Replies)
Discussion started by: Bjoeboo
5 Replies
Login or Register to Ask a Question