Visit Our UNIX and Linux User Community

Top Forums Shell Programming and Scripting Counting a string between 2 strings... Post 302843558 by Don Cragun on Tuesday 13th of August 2013 10:32:30 PM
Old 08-13-2013
With what you have shown us, the following simple awk script seems to do what you want. Since you sometimes have "Task" and sometimes have "task", this script also recognizes "Job" and "job" as synonyms and "Stop" and "stop" as synonyms:
awk '
$1 ~ "[Tt]ask" && $2 ~ "[Ss]top" {t++;next}
$1 ~ "[Jj]ob" && $3 ~ "[Ss]top" {printf("Job %s, %d Tasks\n", $2, t);t=0}
' input

If you try this on a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
This User Gave Thanks to Don Cragun For This Post:
Test Your Knowledge in Computers #1
Difficulty: Medium
The UNIX and Linux Forums ( was founded in 1985.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting occurences of different strings in a file

Hi, i'd like to know if the following is possible with a shell script, and can't find the answer in the search. Suppose i have a logfile build like this: # 8 :riuyzp1028 # 38 : riuyzp1028 # 25 : riuyvzp1032 # 30 : nlkljpa0202 # 1 : nlklja0205 # 38 : riuyzp1028 # 25 :... (4 Replies)
Discussion started by: Freerider
4 Replies

2. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies

3. Shell Programming and Scripting

Counting the max length of string

Hi all, I have a flat file of 1000 rows. I want to check the length of the 5th column. The one having the longest length , I want to set it as DEFINED PARAMETER. So later I can check others with that particular number only. Any ideas ?? (2 Replies)
Discussion started by: ganesh123
2 Replies

4. UNIX for Dummies Questions & Answers

Counting no of lines between two strings in a file

Hi all, I'm very very new to UNIX and AWK world.Please help me in finding a solution for my problem. I'm having a file like this ----------------------------------------------------------------- ~Version Information VERS. 2.0: CWLS log ASCII Standard -VERSION 2.0 WRAP. ... (4 Replies)
Discussion started by: santyshyam
4 Replies

5. Shell Programming and Scripting

Counting string of a variable

Hi, There is a variable f_name, it store some file names. Value of f_name=a.sql b.sql c.sql....... like this. want to count how many file name the var f_name stores. Without using loop is there any command to count that. (5 Replies)
Discussion started by: Dip
5 Replies

6. UNIX for Dummies Questions & Answers

grep -c script counting string twice instead of once?

I tried this script to get a count of the occurrence of a string in files. I have multiple files in one directory I will use this on. All the filenames begin "invALL.06" The script works, except it counts twice for every one instance of 'Invoice Total'. If there are 5 occurences of 'Invoice... (2 Replies)
Discussion started by: scarletsupra
2 Replies

7. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

8. UNIX for Dummies Questions & Answers

Help with counting string elements

Hi All, I hv several files which have hundreds of lines each for example>XYZ.abc01 NNNTCGGTNNNNNCCACACACMYACACACCCACACCCACSCARCAC I'd like to exculde the first line beginning with ">" and then for the rest of the lines get a count for each string element. So for the above example I would like... (8 Replies)
Discussion started by: pawannoel
8 Replies

9. UNIX for Dummies Questions & Answers

counting occurrence of characters in a string

Hello, I have a string like this 0:1:2:0:2:2:4:0:0:0:-200:500...... what i want is to break down how many different characters are there and their count. For example for above string it should display 0 - 5 times 1 - 1 times 2 - 3 times 4 - 1 times . . . I am stuck in writing... (8 Replies)
Discussion started by: exit86
8 Replies

10. Shell Programming and Scripting

Counting Instances of a String with AWK

I have a list of URLs and I want to be able to count the number of instances of addresses ending in a certain TLD and output and sort it like so. 5 48 49 Input is as so (1 Reply)
Discussion started by: Pjstaab
1 Replies
GIT-SH-SETUP(1) 						    Git Manual							   GIT-SH-SETUP(1)

git-sh-setup - Common Git shell script setup code SYNOPSIS
. "$(git --exec-path)/git-sh-setup" DESCRIPTION
This is not a command the end user would want to run. Ever. This documentation is meant for people who are studying the Porcelain-ish scripts and/or are writing new ones. The git sh-setup scriptlet is designed to be sourced (using .) by other shell scripts to set up some variables pointing at the normal Git directories and a few helper shell functions. Before sourcing it, your script should set up a few variables; USAGE (and LONG_USAGE, if any) is used to define message given by usage() shell function. SUBDIRECTORY_OK can be set if the script can run from a subdirectory of the working tree (some commands do not). The scriptlet sets GIT_DIR and GIT_OBJECT_DIRECTORY shell variables, but does not export them to the environment. FUNCTIONS
die exit after emitting the supplied error message to the standard error stream. usage die with the usage message. set_reflog_action Set GIT_REFLOG_ACTION environment to a given string (typically the name of the program) unless it is already set. Whenever the script runs a git command that updates refs, a reflog entry is created using the value of this string to leave the record of what command updated the ref. git_editor runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or EDITOR) on a given file, but error out if no editor is specified and the terminal is dumb. is_bare_repository outputs true or false to the standard output stream to indicate if the repository is a bare repository (i.e. without an associated working tree). cd_to_toplevel runs chdir to the toplevel of the working tree. require_work_tree checks if the current directory is within the working tree of the repository, and otherwise dies. require_work_tree_exists checks if the working tree associated with the repository exists, and otherwise dies. Often done before calling cd_to_toplevel, which is impossible to do if there is no working tree. require_clean_work_tree <action> [<hint>] checks that the working tree and index associated with the repository have no uncommitted changes to tracked files. Otherwise it emits an error message of the form Cannot <action>: <reason>. <hint>, and dies. Example: require_clean_work_tree rebase "Please commit or stash them." get_author_ident_from_commit outputs code for use with eval to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit. create_virtual_base modifies the first file so only lines in common with the second file remain. If there is insufficient common material, then the first file is left empty. The result is suitable as a virtual base input for a 3-way merge. GIT
Part of the git(1) suite Git 01/14/2014 GIT-SH-SETUP(1)

Featured Tech Videos

All times are GMT -4. The time now is 04:33 PM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy