awk can't open file; file merge attempt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk can't open file; file merge attempt
# 1  
Old 09-11-2018
awk can't open file; file merge attempt

Dear all, I have an AWK related issue.

I have two data files; the first, FileA has fewer lines, the second, FileB has more. FileA [75MB] is a subset of FileB [20GB]. Both files are tab delimited.

What I want to do?
When the first two columns for FileA match the first two columns of FileB, I want to print all 24 columns of FileB.
The output file should have a row number == the number of rows in FileA.


I tired this in AWK:
Code:
awk 'BEGIN{OFS="\t"} NR==FNR {f1[$1$2] = $0; next} ($1$2 in f1) {printf "%s",f1[$1$2]; for(i=4; i<=NF; i++) printf "\t%s",$i; printf "\n"}' FileA FileB*> NewFile

When I run, it throws the error:
Code:
" awk: can't open file FileA*
 input record number 1402341, file FileA*
 source line number 1                          ## input number = row number FileA

I can't figure out why this won't work. If someone can, I'd appreciate the help a lot !!

Last edited by rbatte1; 09-11-2018 at 12:40 PM.. Reason: Added CODE tags
# 2  
Old 09-11-2018
Does FileA have an asterisk as its trailing character... "FileA*" or is it simply "FileA"?
# 3  
Old 09-11-2018
Ah! Apologies for the asterisks!

It is just called FileA; there is no trailing asterisk. I think the asterisks may have arisen in conversion to the code boxes that allow for clearer display here.

Anyway, no asterisks either in the files, or in the error readout!

------ Post updated at 06:44 PM ------

Unless I have somehow non-visual characters in the code, which I have mistaken for white space, in which case, that could explain why these asterisks have appeared in each box?
# 4  
Old 09-11-2018
One reason why a utility like awk might see an asterisk and include it in a diagnostic message even though it isn't visible when you cat the script onto your terminal is <backspace> characters in your script file. For example, if what you're seeing on your screen as:
Code:
FileA FileB*> NewFile

actually contained some other text and <backspace>s as in the following:
Code:
FileA FileAB<backspace>* <backspace><backspace><backspace><backspace><backspace><backspace><backspace> B*> NewFile

that would produce the diagnostic message you've shown us from the script you've shown us.

Have you tried using:
Code:
od -bc script_name

to see if there are any invisible characters in your script?
# 5  
Old 09-12-2018
Other findings (that lead to malfunction but hardly relate to your error message).
1.
You don't make use of the OFS, but your input files are tab-separated. So you certainly need
Code:
BEGIN { FS="\t" }

2.
It makes sense to include the FS in the key otherwise $1=1 $2=12 are not distinguishable from $1=11 $2=2
Code:
{ key=($1 FS $2) }

And use key in lieu of $1$2.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to merge fields in a single file using awk ?

Hi, From a file, using: awk -F" " '{ if (NF == 6) print $1, $2, $3, $4, $5, $6; if (NF == 5) print $1, $2, $3, $4, $5; }' i printed out the required output. But i'm trying to merge the columns. Please look at the desired output. Any suggestions? Thanks Output: 00015 PSA1 ... (5 Replies)
Discussion started by: web2moha
5 Replies

2. Shell Programming and Scripting

Awk: cannot open file (No such file or directory)

Hello folks! I am new to Shell and awk scripting. This is my shell script that receives a string as an input from the user from the stdin. #!bin/sh printf "Enter your query\n" read query cmd=`echo $query | cut -f 1 -d " "` input_file=`echo $query | cut -f 2 -d " "` printf $input_file... (10 Replies)
Discussion started by: radiohead_
10 Replies

3. UNIX for Dummies Questions & Answers

merge files along with file names (awk)?

Dear programmers, I have a question about conditionally merging multiple files and having their file names in the first column. Input files: file.1.extension file.2.extension file.3.extension file.4.extension ... file.1000.extension where each file looks like this (with multiple lines):... (5 Replies)
Discussion started by: wei.deng
5 Replies

4. UNIX for Dummies Questions & Answers

file merge using awk

Hi All, I have 2 csv files. 1st file has 10 columns and the 2nd file has 12 columns. The requirement is, if the 4th column of file1 matches with the 4th column of file2, then append the 12th column of file2 with file1. Both files have equal number of lines and the 4th column values are... (1 Reply)
Discussion started by: ganesh_248
1 Replies

5. Shell Programming and Scripting

two file merge with awk

Help I read a file that has 2 fields. look for in a second file the first field and update it with the second field of first file. file1 1131518fat11416.txt ../newaod/2001/04/2001-04-00129233-1.txt file2 INSERT INTO tabric VALUES... (2 Replies)
Discussion started by: mcarlo65
2 Replies

6. Shell Programming and Scripting

please help to merge file with awk or sed

hi experts please help me,thanks in advance file1 arch : x86 install : pass make os : pass make build kernel : pass=100 failed=45 usb storage pass : The Linux Kernel Archives file2 arch : ppc install : failed make os : http://kernel.org (6 Replies)
Discussion started by: yanglei_fage
6 Replies

7. Shell Programming and Scripting

Merge lines in a file with Awk - incorrect output

Hi, I would like: FastEthernet0/0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 output errors, 0 collisions, 0 interface resets Serial1/0:0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort 0... (14 Replies)
Discussion started by: mv652
14 Replies

8. Shell Programming and Scripting

merge two files into one file use awk

Hi, guys. I have one question: I have two files: passwd and shadow (the number of records in these files are not equal)the contents of them are below: passwd: ************** ftp:x:24:24: sshd:x:71:65: uucp:x:10:14: brownj:x:5005:1000: sherrys: x :5006:1000: ... ************* ... (2 Replies)
Discussion started by: daikeyang
2 Replies
Login or Register to Ask a Question