Subroutine or Function Summary


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subroutine or Function Summary
# 8  
Old 08-05-2016
I tried the following code expecting to get

Code:
 
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

However awk prints beyond the line

Code:
 Class (*), Intent (in) :: mold

Here is the file

Code:
 
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 !> \brief Determines if a string is numeric.
 !
 !> \par Example
 !> \code{.f} 
 !>    Character (len=8) :: s;  Logical :: isnum; 
 !> \endcode
 !
 !> \param[in] s     String.
 !> \param[in] fmt   Format descriptor.
 !> \param[in] mold  Scalar or an array of any type. 
 !
 !> \result    True if string represents a numeric value. 

 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Real :: r
 Integer :: i
 Double Precision :: d

 Character (len=65) :: frmt
 Integer :: ios


Last edited by kristinu; 08-05-2016 at 09:44 PM..
# 9  
Old 08-06-2016
It seemed to work for me on my system

Hi.

I used:
Code:
awk '/^ *Subroutine/ || /^ *Function/ {p=1} !NF {p=0} p' <input file>

on the code in post #8 and it produced:
Code:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

on a system:
Code:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.4 (jessie) 
awk GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2-p3, GNU MP 6.0.0)

Best wishes ... cheers, drl
# 10  
Old 08-06-2016
I am using Trisquel 7
# 11  
Old 08-06-2016
Hi.

I was going to install Trisquel 7 in a Virtual Machine to see if I could duplicate your problem until I read this in a recent forum thread there:
Quote:
This distribution seems to be slowly dying and this is the main reason why I'll be leaving as soon as I get the time to do so. There is NO communication whatsoever with the community. We don't know what's going on; we are not informed about the future plans of the maintainers, there have been NO package updates for months and security-critical bugs just remain open without anyone from the development team commenting.
-- I'm leaving Trisquel | Trisquel GNU/Linux - Run free!

So I will just post this set of 4 solutions from my main distribution, 3 of which will probably be accessible to most people:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate text-block extraction, Fortran header.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C awk sed perl debb
what ~/bin/debb

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results, awk:"
awk '/^ *Subroutine/ || /^ *Function/ {p=1} !NF {p=0} p' $FILE

pl " Results, sed:"
# sed -n -r '/^ *Subroutine/|/^ *Function/,/^[   ]*$/p' $FILE
sed -n -r '/(^ *Subroutine)|(^ *Function)/,/^[   ]*$/p' $FILE

pl " Results, perl:"
perl -n -e 'print if /(^ *Subroutine)|(^ *Function)/../^[       ]*$/' $FILE

pl " Results, debb:"
debb '(^ *Subroutine)|(^ *Function)' '^[        ]*$' e et -- $FILE

exit 0

producing:
Code:
./s1 data2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.4 (jessie) 
bash GNU bash 4.3.30
awk GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2-p3, GNU MP 6.0.0)
sed (GNU sed) 4.2.2
perl 5.20.2
debb (local) 1.17
debb    Delete, Extract Bounded Blocks of text, delimiters kept or omitted.

-----
 Input data file data2:
 
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 !> \brief Determines if a string is numeric.
 !
 !> \par Example
 !> \code{.f} 
 !>    Character (len=8) :: s;  Logical :: isnum; 
 !> \endcode
 !
 !> \param[in] s     String.
 !> \param[in] fmt   Format descriptor.
 !> \param[in] mold  Scalar or an array of any type. 
 !
 !> \result    True if string represents a numeric value. 

 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Real :: r
 Integer :: i
 Double Precision :: d

 Character (len=65) :: frmt
 Integer :: ios
 End function str_numeric
 ! Extraneous stuff 1
 ! Extraneous stuff 2
 Subroutine yam ( x )
 Real x

 write(6,*) " Hello from yam."
 End subroutine yam

-----
 Results, awk:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold
 Subroutine yam ( x )
 Real x

-----
 Results, sed:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Subroutine yam ( x )
 Real x


-----
 Results, perl:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Subroutine yam ( x )
 Real x


-----
 Results, debb:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold
 Subroutine yam ( x )
 Real x

Good luck (on all accounts) ... cheers, drl

---------- Post updated at 21:57 ---------- Previous update was at 20:41 ----------

Hi.

Here is the result on trisquel-7:
Code:
./s1 data2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.13.0-39-lowlatency, x86_64
Distribution        : Trisquel GNU/Linux 7.0 
bash GNU bash 4.3.11
awk - ( /usr/bin/awk, 2016-08-06 )
sed (GNU sed) 4.2.2
perl 5.18.2
debb (local) 1.17
debb    Delete, Extract Bounded Blocks of text, delimiters kept or omitted.

-----
 Input data file data2:
 
!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 !> \brief Determines if a string is numeric.
 !
 !> \par Example
 !> \code{.f} 
 !>    Character (len=8) :: s;  Logical :: isnum; 
 !> \endcode
 !
 !> \param[in] s     String.
 !> \param[in] fmt   Format descriptor.
 !> \param[in] mold  Scalar or an array of any type. 
 !
 !> \result    True if string represents a numeric value. 

 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Real :: r
 Integer :: i
 Double Precision :: d

 Character (len=65) :: frmt
 Integer :: ios
 End function str_numeric
 ! Extraneous stuff 1
 ! Extraneous stuff 2
 Subroutine yam ( x )
 Real x

 write(6,*) " Hello from yam."
 End subroutine yam

-----
 Results, awk:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold
 Subroutine yam ( x )
 Real x

-----
 Results, sed:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Subroutine yam ( x )
 Real x


-----
 Results, perl:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold

 Subroutine yam ( x )
 Real x


-----
 Results, debb:
 Function str_numeric  &
   (                   &
     s, fmt, mold      &
   )                   &
     Result (b)
   !
 Logical :: b
 Character (len=*), Intent (in) :: s, fmt
 Class (*), Intent (in) :: mold
 Subroutine yam ( x )
 Real x

I see that there is also a gawk available. That might be useful to install.

Best wishes ... cheers, drl
# 12  
Old 08-07-2016
Did you try the suggestion by rdrtx1 in post #7?

Most likely you file has characters that should not be there, like DOS/Windows-style CR characters, so the empty lines are never empty.
You can also check your file with od -c.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to convert FORTRAN subroutine to awk function?

Hi All I am trying to convert some Fortran subroutine to awk function , those who know kindly explain how to define function in awk, and how to call function Fortran subroutine looks somewhat like this SUBROUTINE GDATE (JD, YEAR,MONTH,DAY) C C---COMPUTES THE GREGORIAN CALENDAR DATE... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

2. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

3. UNIX for Dummies Questions & Answers

Help with Subroutine

Okay I have a 1TB drive that is almost completely full with vids. I am in the process of converting them to mp4. I have two scripts right now. One is a shell script to convert them with Handbrake. The other is a script to get a sort of progress report. To make things easier to understand, I will... (0 Replies)
Discussion started by: Dalton63841
0 Replies

4. Shell Programming and Scripting

getopts not updating from subroutine.

So, I'm running a script with a couple of subroutines, one of which takes arguments using getopts. The first time i call the subroutine everything works as expected, the second time I call it none of the arguments change. Here's a small section of code that shows this behavior. #!/bin/sh... (3 Replies)
Discussion started by: dhibbit
3 Replies

5. Shell Programming and Scripting

Running more than one function from a subroutine

Hi All I am new to perl so had one question. I have one Subroutine which works as expected and below is just an example. where I ran a command and check the output. so my question is if I have more than one command then how to check the results, meaning I want to add more command and check... (2 Replies)
Discussion started by: tannu
2 Replies

6. Shell Programming and Scripting

Using Subroutine / Function in case statement

I have issue running functions under case statement #!/bin/bash single() { Commands } multiple() { Commands } until ; do echo -e " \t \t M A I N - M E N U Perforce delete script \n" (1 Reply)
Discussion started by: sriram003
1 Replies

7. Programming

Subroutine Hung

Hi friends I am Administrator for a system works with uinx OS but, many times I get messages from server console inform me about Subroutine is Hanging so what can I do to reset this Subroutine? Note: always when I got that I restart the server but I think that is not professional solution. (3 Replies)
Discussion started by: bintaleb
3 Replies

8. AIX

Using the passwdpolicy() subroutine.

Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine. I'm not asking for homework, or for someone to... (0 Replies)
Discussion started by: syndex
0 Replies
Login or Register to Ask a Question