BEGIN { FS=OFS="|" }
{
n = split($3, f, ",")
for ( i=1; i<=n; i++ ) {
$3 = f[i]
print
}
)
I am looking at the way to parameterize Field and column delimiters used in above awk command.. Please advise.
BEGIN { FS=OFS="|" }
{
n = split($3, f, ",")
for ( i=1; i<=n; i++ ) {
$3 = f[i]
print
}
)
I am looking at the way to parameterize Field and column delimiters used in above awk command.. Please advise.
Embedded awk script:
#!/bin/bash
awk -v FS="|" -v CS="," '
BEGIN { OFS=FS; if (CS == "") CS="," }
{
n = split($3, f, CS)
for ( i=1; i<=n; i++ ) {
$3 = f[i]
print
}
}
' inputfile
Executable awk script:
#!/usr/bin/awk -f
BEGIN { OFS=FS; if (CS == "") CS="," }
{
n = split($3, f, CS)
for ( i=1; i<=n; i++ ) {
$3 = f[i]
print
}
}
and run it as
/path/to/scriptname.awk -v FS="|" -v CS="," inputfile