learningawk
Technical User
Hi,
I have done a search on previous submissions and found some help on this but my example doesn't quite work.
I want to replace from all filenames in a directory all commas and 1 or more whitespace with a single underscore.
If the file name has a " in it, i want to just remove it.
Here's my awk script so far:
{
if (FNR==1) {
if (NR>1) close(fn)
if (match($0,/[ ,]/)) {gsub(/[ ,]/, "_",$0)
if (match($0,/["]/)) {gsub(/["]/, "",$0) }
}
}
and here's a test of file names:
file1 record 1.dat
file1,record 2.dat
file1 ,"record"3.dat
I want the output to become:
file1_record_1.dat
file1_record_2.dat
file1__record3.dat
I have done a search on previous submissions and found some help on this but my example doesn't quite work.
I want to replace from all filenames in a directory all commas and 1 or more whitespace with a single underscore.
If the file name has a " in it, i want to just remove it.
Here's my awk script so far:
{
if (FNR==1) {
if (NR>1) close(fn)
if (match($0,/[ ,]/)) {gsub(/[ ,]/, "_",$0)
if (match($0,/["]/)) {gsub(/["]/, "",$0) }
}
}
and here's a test of file names:
file1 record 1.dat
file1,record 2.dat
file1 ,"record"3.dat
I want the output to become:
file1_record_1.dat
file1_record_2.dat
file1__record3.dat