bash script using awk

Micro-star international / Ms-7550
July 2, 2009 at 12:49:27
Specs: Microsoft Windows XP Professional, 2.6 GHz / 2047 MB
Hello all, I need to create a bash script that
looks at a file and returns the block sizes. I
have this and it's not right.
awk '$1 !~ /total/ {printf "%-32s %s\n", $9,$3 ;}'
$filename > "$HOME"/bin/bcount.

The input file is this:

a /u/propxrefs/superior-040808/BULK K XREF 
1026 tape blocks
a /u/propxrefs/superior 040808/BULKNXREF 
9405 tape blocks
a /u/propxrefs/superior-040808/BULKRXREF 
1494 tape blocks
a /u/propxrefs/superior-040808/BULKSXREF 
10210 tape blocks
a /u/propxrefs/superior 040808/BULKT XREF 
1844 tape blocks
a /u/propmtrs/BULKMTNKS 32 tape blocks
a /u/propmtrs/BULKMACCT 255 tape blocks
a /u/propmtrs/BULKMSUMH 1023 tape blocks
a /u/propmtrs/BULKREAD 8180 tape blocks

Notice filename may have blanks. My
technique is to look for the word 'tape' and
then take the prior field. Not sure how to do
this in bash.

Thanks Gary

See More: bash script using awk

Report •

July 3, 2009 at 04:07:55
This pure NT batch script does the job. Don't miss the double quotes embracing the filename and beware it is not tested, so report if anything goes wrong.

:: SCANSZ.BAT Usage: scansz "Pathname_Filename"
@echo off & setlocal EnableDelayedExpansion
for /F "delims=" %%j in ('type "%~1"') do call :SIZE %%j
goto :EOF

  set size=
  for %%k in (%*) do (
    if %%k==tape (echo. block size is !size! & goto :EOF)
    set size=%%k
  goto :EOF
:: End_Of_Batch

Report •

July 3, 2009 at 09:32:57
@IVO, he needs a bash script,
@OP, here's your one liner...

C:\test>gawk "{print $(NF-2)}" file.txt

GNU win32 packages | Gawk

Report •

July 3, 2009 at 12:48:38
The OP reported MS Windows XP Pro as operating system, so my script; he might want to scan the file under Windows, otherwise better to post Linux/Unix as OS.

Report •

Related Solutions

July 3, 2009 at 18:02:41
>> otherwise better to post Linux/Unix as OS.

we can see from the title and his first line of the paragraph that he want a bash script. If OS is indeed Windows, then we can further deduce he might be using cygwin. (Or just plain gawk.exe downloaded from GNU). I would find it strange with OP if he were to want to use a batch when he is already using better tools for the on his system.

GNU win32 packages | Gawk

Report •

Ask Question