Extracting columns from multiple files with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting columns from multiple files with awk
# 8  
Old 09-22-2010
Quote:
Originally Posted by posix
with the help of cut and paste you can get the result
Code:
$cut -f3 file7.txt >temp1.txt
$cut -f3 file8.txt >temp2.txt
$paste temp1.txt temp2.txt >file.txt

Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '{printf s $3;s=FS}END{print ""}' file1 file2 file3 file4

awk '{printf s $3; s=F}END{print ""}' dom1of5.txt dom2of5.txt dom3of5.txt dom4of5.txt
awk: run time error: not enough arguments passed to printf("Oil[%]")
FILENAME="dom1of5.txt" FNR=1 NR=1
Oil[

---------- Post updated at 11:27 AM ---------- Previous update was at 11:19 AM ----------

Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '{printf s $3;s=FS}END{print ""}' file1 file2 file3 file4

awk '{printf s $3; s=FS}END{print ""}' dom1of5.txt dom2of5.txt dom3of5.txt dom4of5.txt
awk: run time error: not enough arguments passed to printf("Oil[%]")
FILENAME="dom1of5.txt" FNR=1 NR=1
Oil[

---------- Post updated at 11:27 AM ---------- Previous update was at 11:27 AM ----------

Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '{printf s $3;s=FS}END{print ""}' file1 file2 file3 file4

I'm not sure if I typed it correctly:
awk '{printf s $3; s=FS}END{print ""}' dom1of5.txt dom2of5.txt dom3of5.txt dom4of5.txt
awk: run time error: not enough arguments passed to printf("Oil[%]")
FILENAME="dom1of5.txt" FNR=1 NR=1
Oil[
# 9  
Old 09-22-2010
Sorry, printf doesn't work like that with some awk versions, try this:
Code:
awk '{printf("%s%s", s, $3);s=FS}END{print ""}' dom1of5.txt dom2of5.txt dom3of5.txt dom4of5.txt

# 10  
Old 09-22-2010
You should use FNR (not NR) to control multiple files.

Code:
awk '{a[FNR]=a[FNR] FS $2;t=(FNR>T)?FNR:t}END {for (i=1;i<=t;i++) print a[i]}'  file1 file2 file3 file4

This User Gave Thanks to rdcwayx For This Post:
# 11  
Old 09-23-2010
Quote:
Originally Posted by rdcwayx
You should use FNR (not NR) to control multiple files.

Code:
awk '{a[FNR]=a[FNR] FS $2;t=(FNR>T)?FNR:t}END {for (i=1;i<=t;i++) print a[i]}'  file1 file2 file3 file4

Could you please elaborate the code, some where i missed the logic.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending different columns of multiple files in awk

Hello All, I have three input files cat file1 col1|col2|col3 a|1|A b|2|B cat file2 col1|col2|col3 c|3|C cat file3 col1|col2|col3 d|4|D e|5|E i want below output file4 col1|col2 a|1 (6 Replies)
Discussion started by: looney
6 Replies

2. Shell Programming and Scripting

Joining files using awk not extracting all columns from File 2

Hello All I'm joining two files using Awk by Left outer join on the file 1 File 1 1 AA 2 BB 3 CC 4 DD File 2 1 IND 100 200 300 2 AUS 400 500 600 5 USA 700 800 900 (18 Replies)
Discussion started by: venkat_reddy
18 Replies

3. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

4. Shell Programming and Scripting

awk arrays comparing multiple columns across two files.

Hi, I'm trying to use awk arrays to compare values across two files based on multiple columns. I've attempted to load file 2 into an array and compare with values in file 1, but success has been absent. If anyone has any suggestions (and I'm not even sure if my script so far is on the right lines)... (4 Replies)
Discussion started by: hubleo
4 Replies

5. Shell Programming and Scripting

awk script to split file into multiple files based on many columns

So I have a space delimited file that I'd like to split into multiple files based on multiple column values. This is what my data looks like 1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH 1ku1A02 1 10... (9 Replies)
Discussion started by: viored
9 Replies

6. Shell Programming and Scripting

Extracting multiple columns with awk

Hi everyone!! I need to apply a simple command to extract columns from a matrix, but I need to extract contemporary from the first to the tenth columns, than from the eleventh to the twentyth and so on... how can i do that? (1 Reply)
Discussion started by: gabrysfe
1 Replies

7. Shell Programming and Scripting

extracting columns falling within specific ranges for multiple files

Hi, I need to create weekly files from daily records stored in individual monthly filenames from 1999-2010. my sample file structure is like the ones below: daily record stored per month: 199901.xyz, 199902.xyz, 199903.xyz, 199904.xyz ...199912.xyz records inside 199901.xyz (original data... (4 Replies)
Discussion started by: ida1215
4 Replies

8. UNIX for Dummies Questions & Answers

Extracting columns from multiple files with awk

hi everyone! I already posted it in scripts, I'm sorry, it's doubled I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is: awk 'NR==FNR{a=$2; next}... (1 Reply)
Discussion started by: orcaja
1 Replies

9. Shell Programming and Scripting

extracting multiple consecutive columns using awk

Hello, I have a matrix 200*10,000 and I need to extract the columns between 40 and 77. I dont want to write in awk all the columns. eg: awk '{print $40, $41, $42,$43 ... $77}'. I think should exist a better way to do this. (10 Replies)
Discussion started by: auratus42
10 Replies

10. Shell Programming and Scripting

awk 3 files to one based on multiple columns

Hi all, I have three files, one is a navigation file, one is a depth file and one is a file containing the measured field of gravity. The formats of the files are; navigation file: 2006 320 17 39 0 0 *nav 21.31542 -157.887 2006 320 17 39 10 0 *nav 21.31542 -157.887 2006 320 17 39 20 0... (2 Replies)
Discussion started by: andrealphus
2 Replies
Login or Register to Ask a Question