Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.
filename=$HOME/bin/BOUTPUT
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 blocksNotice 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

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 :SIZE set size= for %%k in (%*) do ( if %%k==tape (echo. block size is !size! & goto :EOF) set size=%%k ) goto :EOF :: End_Of_Batch

@IVO, he needs a bash script,
@OP, here's your one liner...
C:\test>gawk "{print $(NF-2)}" file.txt
1026
9405
1494
10210
1844
32
255
1023
8180

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.

>> 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.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |