6

Append one file,

011C0201.WAV
011C0202.WAV
011C0203.WAV
011C0204.WAV
011C0205.WAV

After another file,

52 601
39 608
56 1016
39 416
65 335

result is the following, also divide by tab

011C0201.WAV    52_601_011C0201
011C0202.WAV    39_608_011C0202
011C0203.WAV    56_1016_011C0203
011C0204.WAV    39_416_011C0204
011C0205.WAV    65_335_011C0205

Here is what I do

awk '
NR==FNR { start=$1; end=$2; next}
{ print $0 start end }
' WSJ_310P_PC_16k.epd WSJ_310P_PC_16k.spt > tmp

But it is not working. What am I doing wrong?

6

How about paste + awk?

$ paste one another | 
    awk '{print $1, $2 "_" $3 "_" substr($1,1,length($1)-4)}' OFS='\t'
011C0201.WAV    52_601_011C0201
011C0202.WAV    39_608_011C0202
011C0203.WAV    56_1016_011C0203
011C0204.WAV    39_416_011C0204
011C0205.WAV    65_335_011C0205

If you prefer to do it entirely in awk:

awk 'NR==FNR {a[FNR]=$0; next} {print a[FNR], $1 "_" $2 "_" substr(a[FNR],1,length(a[FNR])-4)}' OFS='\t' one another
5

Here is one using pure awk

awk '
    NR==FNR {a[NR]=$0; next}
    {
        split(a[FNR],b,".");
        printf "%s\t%s_%s_%s\n", a[FNR], $1, $2, b[1]
    }
' file1 file2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.