Sponsored Content
Top Forums Shell Programming and Scripting How to get lines with only one occurence of pattern? Post 302988219 by Scrutinizer on Thursday 22nd of December 2016 02:49:36 AM
Old 12-22-2016
You cannot do this with a single basic regular expression. You need to either count the number like some solutions do or use multiple regexes.

A variation on Chubler XL's approach with two regexes:
Code:
sed '/MODE.*MODE/d; /MODE/!d' file

Or counting the number of occurrences:
Code:
awk -FMODE 'NF==2' file


Last edited by Scrutinizer; 12-22-2016 at 05:02 AM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pattern occurence in a file

How can we find the number of occurence of a specified pattern in a file? This command would be a part of a shell script. (5 Replies)
Discussion started by: videsh77
5 Replies

2. Shell Programming and Scripting

Perl onliner to search the last line with an occurence of a pattern

Hi I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it. similar to grep 'pattern' filename | tail -1 in UNIX Ex: I want to display the line starting with "cool" and which is a last occurence adadfadafadf adfadadf cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 Replies

3. Shell Programming and Scripting

Sed and replacing one occurence of pattern

I would like to use sed to replace one occurence of a pattern in a file. When I use the s/// command it replaces all occurences of the pattern in the file. Should I be using something other than sed? Thanks (6 Replies)
Discussion started by: ss9u
6 Replies

4. Shell Programming and Scripting

How to identify the occurence of a pattern between a unique character?

hi, is it possible to find the number of occurences of a pattern between two paranthesis. for e.g i have a file as below. >>{ >>hi >>GoodMorning >>how are you? >>} >>is it good, >>tell me yes, if it is good In the above file, its clear the occurence of word "Good"... (17 Replies)
Discussion started by: divak
17 Replies

5. Shell Programming and Scripting

Printing the continuous occurence of pattern using awk ?

Hello all, I have a input file like this. input file --------------- abc ab001 + ab002 zca acb ab006 + ab007 caz cba ab003 + ab004 zca bac ab004 - ab005 zac bca ab002 - ab003 cza cba ab005 + ab006 acz cba ab005 ... (5 Replies)
Discussion started by: admax
5 Replies

6. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

7. Shell Programming and Scripting

Help with using awk to print pattern/occurence

Hi, Do anybody know how to use awk to count the pattern at specific column? Input file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a . . Output file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3 . . I plan to count how many "miR" in column 3... (2 Replies)
Discussion started by: cpp_beginner
2 Replies

8. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

9. UNIX for Dummies Questions & Answers

Vi delete line with second occurence of pattern

I have a large file and many lines are duplicated. I'm trying to delete lines with every second occurrence of a pattern. Did tried searching similar question but no luck. I can delete all lines matching pattern with :g/pattern/d but don't want to lose data. Sample pattern to delete... (6 Replies)
Discussion started by: homer4all
6 Replies

10. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies
hbpldecode(1)						      General Commands Manual						     hbpldecode(1)

NAME
hbpldecode - Decode a HBPL stream into human readable form. SYNOPSIS
hbpldecode [options] <hbpl-file DESCRIPTION
hbpldecode decodes a HBPL stream into human readable form. A HBPL stream is the printer langauge used by the Fuji-Xerox cp105b and the Dell 1250c printers. COMMAND LINE OPTIONS
These are the options that can appear on the command line. -d basename Basename of .pbm file for saving decompressed planes. -h Print hex file offsets. -o Print file offsets. -D level Set Debug level [0]. EXAMPLES
Decode an HBPL stream file. $ hbpldecode -h 1250c-mono.prn 0: 33%-12345X@PJL JOB MODE=PRINTER 1f: @PJL SET STRINGCODESET=UTF8 3b: @PJL COMMENT DATE=06/01/2011 58: @PJL COMMENT TIME=13:28:30 73: @PJL COMMENT DNAME=empty - Notepad 96: @PJL SET JOBATTR="@LUNA=rick" b4: @PJL SET COPIES=1 c6: @PJL SET QTY=1 d5: @PJL SET JOBATTR="@TRCH=OFF" f2: @PJL SET DUPLEX=OFF 106: @PJL SET BINDING=LONGEDGE 120: @PJL SET RENDERMODE=GRAYSCALE 13e: @PJL SET ECONOMODE=OFF 155: @PJL SET RET=ON 165: @PJL SET JOBATTR="@IREC=OFF" 182: @PJL SET JOBATTR="@HOAD=I0A00020F" 1a5: @PJL SET JOBATTR="@JOAU=rick" 1c3: @PJL SET JOBATTR="@CNAM=RICK-VB" 1e4: @PJL SET IWAMANUALDUP=OFF 1fe: @PJL SET IWAJAMRECOVERY=AUTO 21b: @PJL SET JOBATTR="@MSIP=NORMAL" 23b: @PJL SET PAPERDIRECTION=SEF 257: @PJL SET RESOLUTION=600 26f: @PJL SET BITSPERPIXEL=8 287: @PJL SET JOBATTR="@DRDM=RASTER" 2a7: @PJL SET JOBATTR="@TCPR=33" 2c3: @PJL SET JOBATTR="@TUCR=33" 2df: @PJL SET JOBATTR="@TTRC=33" 2fb: @PJL SET JOBATTR="@TSCR=33" 317: @PJL SET JOBATTR="@GCPR=33" 333: @PJL SET JOBATTR="@GUCR=33" 34f: @PJL SET JOBATTR="@GTRC=33" 36b: @PJL SET JOBATTR="@GSCR=33" 387: @PJL SET JOBATTR="@ICPR=34" 3a3: @PJL SET JOBATTR="@IUCR=34" 3bf: @PJL SET JOBATTR="@ITRC=34" 3db: @PJL SET JOBATTR="@ISCR=34" 3f7: @PJL SET JOBATTR="@TDFT=0" 412: @PJL SET JOBATTR="@GDFT=0" 42d: @PJL SET JOBATTR="@IDFT=0" 448: @PJL ENTER LANGUAGE=HBPL 461: RECTYPE 'A' [0x41]: 462: 81 a1: 0x0 465: 82 a2: 0x7 469: 83 a2: 0x1 46d: RECTYPE 'C' [0x43]: 46e: 91 a1: 0x0 471: 92 a1: 0x1 474: 93 a1: 0x1 477: 94 a1: 0x0 47a: 95 c2: 0x0 480: 96 a1: 0x0 483: 97 c3: 0x0 489: 98 a1: 0x0 48c: 99 a4: 1 [PAGECNT] 492: 9a c4: 5104x6600 [WxH] 49c: 9b a1: 0x0 49f: 9c a1: 0x1 4a2: 9d a1: 0x9 4a5: 9e a1: 0x2 4a8: 9f a1: 0x5 4ab: a0 a1: 0x8 4ae: a1 a1: 0x0 4b1: a2 c4: 5104x6600 [WxH] 4bb: RECTYPE 'Q' [0x51]: 4bc: RECTYPE 'R' [0x52]: 4bd: a3 a1: 0x0 4c0: a4 a2: 6457 (0x1939) bytes of data... 1dfe: RECTYPE 'S' [0x53]: 1dff: RECTYPE 'D' [0x44]: 1e00: RECTYPE 'B' [0x42]: 1dff: 33%-12345X@PJL EOJ FILES
/usr/bin/hbpldecode AUTHOR
Rick Richardson <rick.richardson@comcast.net>
All times are GMT -4. The time now is 03:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy