Sponsored Content
Top Forums Shell Programming and Scripting to grep and print their counts Post 302140528 by radoulov on Saturday 13th of October 2007 03:37:59 PM
Old 10-13-2007
... and another one Smilie

Code:
awk 'NR==FNR{p=$0;next}
{r=FS=$0;$0=p;printf "%s=%d\n",r,NF-1}' file1 file2

Use nawk or /usr/xpg4/bin/awk on Solaris.

Example:
Code:
% cat file1              
ACFCFACCACARCSHFARCVJVASTVAJFTVAJVGHBAJ
% cat file2              
A
C
F
R
% awk 'NR==FNR{p=$0;next}
{r=FS=$0;$0=p;printf "%s=%d\n",r,NF-1}' file1 file2
A=9
C=7
F=4
R=2


Last edited by radoulov; 10-13-2007 at 04:44 PM..
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using grep and print filename

Hi, I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files. I have alot files such that a.txt, b.txt,c.txt...etc. If I found a certain character, I would print that particular filename. I... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

2. Shell Programming and Scripting

Print lines after grep

Hi all, I need help in following scenario. I have a file with about 10,000 lines. There are several lines which have word "START" (all upper case) in them. I want to grep line with word "START" and then do the following 1. Print the line number having word "START" 2. Print the next 11 lines. ... (4 Replies)
Discussion started by: jakSun8
4 Replies

3. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

4. UNIX for Dummies Questions & Answers

Grep & print

I just need to print value 12 digit number after the key *MI*. My big concern is the below lines are not fixed format or length so cant cut based on the position. XSA*00**00**XZ*DA-Paper*30*942411167****MI*010001990802~AEE XSA*00**00**ZZ*EA-aper*30*94169****MI*010001960802~SDRE*ER... (7 Replies)
Discussion started by: gunaah
7 Replies

5. Shell Programming and Scripting

Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

6. Shell Programming and Scripting

Print lines before and after..not grep -A

Hi I have this in my file 2011-04-18 15:32:11 system-alert-00012: UDP flood! From xxxxxx to yyyyyyyyyy, int ethernet0/2). Occurred 1 times. 2011-04-18 15:32:11 system-alert-00012: UDP flood! From xxxxxx to yyyyyyyyyy, int ethernet0/2). Occurred 1 times. 2011-04-18 15:32:11... (9 Replies)
Discussion started by: zorrox
9 Replies

7. UNIX for Dummies Questions & Answers

Grep and Print

Hi , I have data in below pattern 05:00:13,184 WARN ContentTransferService - CTS:createContent - File Name:470208627 Total time taken(ms):5137 05:00:13,184 WARN ContentTransferService - CTS:createContentWithFolderPath(uploadDocument) - File Name:295918481 User Id:xyz Total time... (5 Replies)
Discussion started by: Abhayman
5 Replies

8. Shell Programming and Scripting

Grep patterns and group counts

Hi, I have a continuous log file which has the following format:- 02/Sep/2015: IP 11.151.108.166 error occurred etc 03/Sep/2015: IP 11.151.108.188 error occurred etc 03/Sep/2015: IP 11.152.178.250 error occurred etc 03/Sep/2015: IP 11.188.108.176 error occurred etc 03/Sep/2015: IP... (4 Replies)
Discussion started by: finn
4 Replies
WDCTL(8)						       System Administration							  WDCTL(8)

NAME
wdctl - show hardware watchdog status SYNOPSIS
wdctl [options] [device...] DESCRIPTION
Show hardware watchdog status. The default device is /dev/watchdog. If more than one device is specified then the output is separated by one blank line. Note that number of supported watchdog features is hardware specific. OPTIONS
-f, --flags list Print selected flags only. -F, --noflags Do not print information about flags. -n, --noheadings Do not print a header line for flags table. -I, --noident Do not print watchdog identity information. -T, --notimeouts Do not print watchdog timeouts. -s, --settimeout seconds Set the watchdog timeout in seconds. -o, --output list Define the output columns to use in table of watchdog flags. If no output arrangement is specified, then a default set is used. Use --help to get list of all supported columns. -O, --oneline Print all wanted information on one line in key="value" output format. -V, --version Output version information and exit. -r, --raw Use the raw output format. -x, --flags-only Same as -I -T. -h, --help Print a help text and exit. AUTHORS
Karel Zak <kzak@redhat.com> Lennart Poettering <lennart@poettering.net> AVAILABILITY
The wdctl command is part of the util-linux package and is available from Linux Kernel Archive <ftp://ftp.kernel.org/pub/linux/utils/util- linux/>. util-linux June 2012 WDCTL(8)
All times are GMT -4. The time now is 10:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy