Putting a program on the command-line is usually harder in windows than under unix. This should work.
gawk "length($0)<100{$0=sprintf(\"%-100s\",$0)}1" input_file
If you have mawk, try
mawk "length($0)<100{$0=sprintf('%-100s',$0)}1" input_file
Another way to feed a program to awk:
echo...
Under Solaris, use /usr/xpg4/bin/awk.
This will preserve the spacing between columns.
Put in file "convertfields.awk" and run with
/usr/xpg4/bin/awk -f convertfields.awk /foo
# Produces array of nonmatching and matching
# substrings. The size of the array will
# always be an odd number. The...
awk '/BEGIN/,/END/{next}1' file
works with awk, gawk, and mawk (I just tested it).
You're probably using something antique and obsolete.
If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.
And of...
BEGIN { target = "KnownString" }
/^\+/ { sub( /^\+/, "" ); line = line $0 ; next }
{ process( line )
line = $0
}
END { process( line ) }
function process( line )
{
split( line, ary, /[ \t]+/ )
for (i=1; i in ary; i++)
{ if (target == ary[i])
print ary[i+1]
}
}
Using ~ is one way to see if a reg.ex. matches a string.
BEGIN{ print "foo bar" ~ /o.b/ }
If you have an explicit reg.ex. like /.../, matching
against $0 is automatic:
BEGIN{ $0 = "foo bar"; print /o.b/ }
But if the reg.ex. is disguised as a string, we have to let awk know that we want it...
Here's a more understandable version.
# Are we reading 1st file?
FILENAME==ARGV[1] {
#Convert whitespace in $0 to "|".
gsub( /[ \t]+/, "|" )
# Save our regular expression.
r = $0
# Read next line.
next }
# Print line if it matches the string that
# is being used as a regular...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.