gawk (dos) insert backslash at end of line

I have created with the DOS-command dir a list of a directory.

 Directory of C:\Users\User\Documents

09.06.2011  20:50  48.322 file1.txt
02.11.2010  23:00  9.216 file2.txt
15.12.2010  21:06  26.793 file2.txt

Now i would like to add the directory ahead of the filename. Therefore a backslash needs to be added at the end of $0 or in my case the var p. This does not work, though when I add a word it works.

Output with a string:

gawk" "/ Directory of / {p=substr($0,14)} {if (NF>3) {print p " test " $4}

Output:

C:\Users\User\Documents test file1.txt 48.322
 C:\Users\User\Documents test file2.txt  9.216
 C:\Users\User\Documents test file1.txt 26.793

Can anybody help?

gawk" "/ Directory of / {p=substr($0,14)} {if (NF>3) {print p \"\\\" $4}

All these varietys return an empty file:
{print p \"\\\" $4} = empty file
{print p "\\" $4} = empty fileFB_Addon_TelNo{ height:15px !important; white-space: nowrap !important; background-color: #0ff0ff;}

Hi

Not sure if this is what you wanted. If not, please post the actual output you expected:

$ awk '/ Directory of /{p=substr($0,14)} {if (NF>3){print p""$4;}}' a
 C:\Users\User\Documents\file1.txt
 C:\Users\User\Documents\file2.txt
 C:\Users\User\Documents\file2.txt

Guru.

In what environment do you run gawk? In DOS?

Sorry, made a mistake. The directory looks like this without backslash at the end.

Directory of C:\Users\User\Documents  
09.06.2011  20:50  48.322 file1.txt 
02.11.2010  23:00  9.216 file2.txt 
15.12.2010  21:06  26.793 file2.txt

Desired output with backslash between the var p and filename
C:\Users\User\Documents\file1.txt
C:\Users\User\Documents\file2.txt
C:\Users\User\Documents\file2.txt

---------- Post updated at 06:05 PM ---------- Previous update was at 01:58 PM ----------

Yes the operating system is Windows 7 on Command line with dos. Since i can't get the backslash to be passed. How about getting this backslash with getline < backslash.txt containing only the backslash. Can somebody help on the code for file input in an one liner?

How about:

var=sprintf("%c", 0134);

where 0134 is the octal value of a backslash. Then you can use that var wherever you like. print var "stuff" prints \stuff

1 Like

This should work:

gawk "/Directory of/{p=$NF; next} NF{printf(\"%s%c%s\n\", p, 0x5C, $NF)}" file
1 Like

With this sample

var=sprintf("%c", 0134);

I got the idea to assign

-v bs=\

Even this works as a FS for the split() command

-v bs=[\._]

This finally worked best with DOS

 
gawk -v bs=\ "/ Directory of / {p=substr($0,14)} {if (NF>3) {print p bs $4}"
1 Like