Computing.Net > Forums > Programming > bash script using awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

bash script using awk

Reply to Message Icon

Name: dccgary
Date: July 2, 2009 at 12:49:27 Pacific
OS: Microsoft Windows XP Professional
CPU/Ram: 2.6 GHz / 2047 MB
Product: Micro-star international / Ms-7550
Subcategory: General
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: July 3, 2009 at 04:07:55 Pacific
Reply:

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


0

Response Number 2
Name: ghostdog
Date: July 3, 2009 at 09:32:57 Pacific
Reply:

@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

GNU win32 packages | Gawk


0

Response Number 3
Name: IVO
Date: July 3, 2009 at 12:48:38 Pacific
Reply:

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.


0

Response Number 4
Name: ghostdog
Date: July 3, 2009 at 18:02:41 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: bash script using awk

Bash script to start application www.computing.net/answers/programming/bash-script-to-start-application/18255.html

How to compare 2 files using awk? www.computing.net/answers/programming/how-to-compare-2-files-using-awk/15598.html

Shell Script with AWK www.computing.net/answers/programming/shell-script-with-awk/15486.html