To cut entire column from a file and apend it to another file as another column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To cut entire column from a file and apend it to another file as another column
# 1  
Old 04-22-2008
To cut entire column from a file and apend it to another file as another column

file1.txt :
india pakistan bangladesh
japan canada africa
USA srilanka Nepal

file2.txt
Delhi
Tokyo
washington

I have to cut the first column of file1.txt and apend it with file2.txt as another column like this

Delhi india
Tokyo japan
washington USA

Anyone one please say me the syntax for the above .

Last edited by sakthifire; 04-22-2008 at 09:46 AM..
# 2  
Old 04-22-2008
A possible way :
Code:
awk '{print $1}' file1.txt | paste -d' ' file2.txt -

awk can replaced by cut :
Code:
cut -d' ' -f1 file1.txt  | paste -d' ' file2.txt -

Jean-Pierre.
# 3  
Old 04-22-2008
in a single command
Code:
awk 'BEGIN{ while ( getline < "secondfile" ) { arr[i++]=$0 } }{ print arr[j++], $1 }' firstfile

# 4  
Old 04-23-2008
Thank you ...

Its working fine...
# 5  
Old 06-25-2008
It's Simple Buddy

Quote:
Originally Posted by sakthifire
file1.txt :
india pakistan bangladesh
japan canada africa
USA srilanka Nepal

file2.txt
Delhi
Tokyo
washington

I have to cut the first column of file1.txt and apend it with file2.txt as another column like this

Delhi india
Tokyo japan
washington USA

Anyone one please say me the syntax for the above .
Just Use Simple Cmd :
First Cut fhe first field of first file
$ cut -d' ' -f1 <first filename> > tmpfirst
$ cut -d' ' -f2 <second filename> > tmpsecond
$ paste tmpfirst tmpsecond > newfile
(-f1 means first field , -f2 means second field)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

2. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies

3. UNIX for Dummies Questions & Answers

Fill csv entire column with content from another text file

I have a csv that looks like this: ,yude-to-nap2,0,0,0,0,0 ,2twis-yude-to-nap2,0,0,0,0,0 ,2tiws-yude-to-nap2,0,0,0,0,0 ,2arcos-yude-to-nap2,0,0,0,0,0 and another file named m1 that has a single line of text as content: Feb 1 15:30:20 How can I fill the whole the empty column of the... (1 Reply)
Discussion started by: RobertoRivera
1 Replies

4. Shell Programming and Scripting

Delete an entire column from a tab delimited file

Hi, Can anyone please tell me about how we can delete an entire column from a tab delimited file? Mu input_file.txt looks like this: And I want the output as: I used the below code nawk -v d="1" 'BEGIN{FS=OFS="\t"}{$d=""}{print}' input_file.txtBut in the output, the first column is... (5 Replies)
Discussion started by: sampoorna
5 Replies

5. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

6. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

7. Shell Programming and Scripting

edit entire column from a fixed-width file using awk or sed

Col1 Col2 Col3 Col4 12 Completed 08 0830 12 In Progress 09 0829 11 For F U 07 0828 Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
Discussion started by: tamahomekarasu
10 Replies

8. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

9. UNIX for Advanced & Expert Users

Updating entire column irrespective of any data in a file

Hi, I have a file A.txt (tab separated) as below: pavan chennai/tes/bangalore 100 sunil mangalore/abc/mumbai 230 kumar delhi/nba/andhra 310 I want to change only second column as below . Rest of columns as it is ;The ouput file is also tab... (4 Replies)
Discussion started by: kpavan2004
4 Replies

10. Shell Programming and Scripting

cut the third column from a file

I have a text file which has the following data. There can be more lines in the file. But, I am only interested in these two lines which has ~ZZ~VISTN and ~ZZ~F159B segments. ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183 7~U~00200~000011258~0~P~< ... (8 Replies)
Discussion started by: isingh786
8 Replies
Login or Register to Ask a Question