Sponsored Content
Top Forums Shell Programming and Scripting sed pattern matching question Post 302518171 by mirni on Thursday 28th of April 2011 07:33:55 PM
Old 04-28-2011
Quote:
From what I can tell the whole string (ABCD|/p) is a literal.
Mmmmm... no.
The string 'ABCD|' is a literal, the rest '/p' is the end of regex ('/') and print command ('p'). So the first sed command
Code:
sed -n -e '/^.*ABCD|/p'

is an instruction to print only lines containing 'ABCD|'. There is some redundancy there; the following would do the same:
Code:
sed -n -e '/ABCD|/p'

The second sed removes the beginning of line until ABCD| including. Note that matching here is greedy, so if you have multiple instances of ABCD| there, the pattern is gonna match the longest possible substring. E.g.:
Code:
$ echo "blah|ABCD|hhhh|fals.;and&+324ABCD|ooo|ABCD" | sed -e 's/^.*ABCD|//' 
ooo|ABCD

The third one removes trailing '|ABCD'

We could simplify this as :
Code:
sed -n '/ABCD|/{  #do the following on lines containing "ABCD|"
            s/^.*ABCD|// ;  #eat the longest substring from beginning to "ABCD|"
            s/|ABCD$//;     # eat the  last "|ABCD" just before end of line
            p }'               # and print it


Last edited by mirni; 04-28-2011 at 08:40 PM..
This User Gave Thanks to mirni For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pattern matching + perl question

i can only find the first occurance of a pattern how do i set it to loop untill all occurances have changed. #! /usr/bin/perl use POSIX; open (DFH_FILE, "./dfh") or die "Can not read file ($!)"; foreach (<DFH_FILE>) { if ($_ !~ /^#|^$/) { chomp; ... (1 Reply)
Discussion started by: Optimus_P
1 Replies

2. Shell Programming and Scripting

Pattern matching question

Hi guys, I have the following expression : typeset EXBYTEC_CHK=`egrep ^"+${PNUM}" /bb/data/firmexbytes.dta` can anybody please explain to me what ^"+${PNUM}" stands for in egrep statement? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

3. Shell Programming and Scripting

SED Question: Search and Replace start of line to matching pattern

Hi guys, got a problem here with sed on the command line. If i have a string as below: online xx:wer:xcv: sdf:/asdf/http:https-asdfd How can i match the pattern "http:" and replace the start of the string to the pattern with null? I tried the following but it doesn't work: ... (3 Replies)
Discussion started by: DrivesMeCrazy
3 Replies

4. Shell Programming and Scripting

Pattern matching question

Hi, I am writing a simple log parsing system and have a question on pattern matching. It is simply grep -v -f patterns.re /var/log/all.log Now, I have the following in my logs Apr 16 07:33:17 ad-font-dc1 EvntSLog: AD-FONT-DC1/NTDS ISAM (700) - "NTDS (384) NTDSA: Online defragmentation... (5 Replies)
Discussion started by: wpfontenot
5 Replies

5. Shell Programming and Scripting

pattern matching question

Hi guys, I have a file in the following format: 4222 323K 323L D222 494 8134 A023 A024 49 812A 9871 9872 492 A961 A962 A963 491 0B77 0B78 0B79 495 0B7A 0B7B 0B7C 4949 WER9 444L 999O I need to grep the line... (5 Replies)
Discussion started by: aoussenko
5 Replies

6. Shell Programming and Scripting

Pattern matching question

Hi Guys, I am trying to setup a check for the string using an "if" statement. The valid entry is only the one which contain Numbers and Capital Alpha-Numeric characters, for example: BA6F, BA6E, BB21 etc... I am using the following "if" constract to check the input, but it fails allowing Small... (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Shell Programming and Scripting

pattern matching question

Hi Guys I am trying to check if the pattern "# sign followed by one or several tabs till the end of the line" exists in my file. I am using the following query: $ cat myfile | nawk '{if(/^#\t*$/) print "T"}' Unfortunately it does not return the desired output since I know for sure that the line... (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

pattern matching question

Hi guys I have the following case statement in my script: case $pn.$db in *?.fcp?(db)) set f ${pn} cp ;; *?.oxa?(oxa) ) set oxa $pn ;; esac Can somebody help me to understand how to interpret *?.fcp?(db)) or *?.oxa?(oxa) ? I cannot figure out how in this case pattern maching... (5 Replies)
Discussion started by: aoussenko
5 Replies

9. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

10. Shell Programming and Scripting

Bash pattern matching question

I need to check the condition of a variable before the script continues and it needs to match a specific pattern such as EPS-03-0 or PDF-02-1. The first part is a 3 or 4 letter string followed by a hyphen, then a 01,02 or 03 followed by a hyphen then a 0 or a 1. I know I could check for every... (4 Replies)
Discussion started by: stormcel
4 Replies
MBR_CHECK_MEMBERSHIP(3) 				   BSD Library Functions Manual 				   MBR_CHECK_MEMBERSHIP(3)

NAME
mbr_check_membership, mbr_check_service_membership -- check whether a user is a member of a group or service ACL SYNOPSIS
#include <membership.h> int mbr_check_membership(uuid_t user, uuid_t group, int *ismember); int mbr_check_service_membership(uuid_t user, const char *service, int *ismember); DESCRIPTION
mbr_check_membership() tests if a given user is a member of a group (either direct or indirect via a nested group). ismember is set to 1 if the user is a member or 0 if not a member of the group. mbr_check_service_membership() similarly tests if a given user is a member of a ser- vice ACL group. Service ACLs are special groups defined with the prefix "com.apple.access_". The service is then prefixed (e.g., "afp" would check "com.apple.access_afp"). There is a special group that grants accessto all services called "com.apple.access_all_services". Users may belong to any number of groups. mbr_check_membership() should always be used to check group membership, rather than calling getgroups(2) or getgrouplist(2). The setgroups(2) and getgroups(2) routines are limited to a fixed number of gids, and so may not include all of a user's groups. There are two special cases. If the two uuids are equal, then ismember is set to 1. If the group uuid is equal to the reserved "everyone" uuid (ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000000C), then ismember will be set to 1 for any valid user. Group membership information is managed by opendirectoryd(8). RETURN VALUES
mbr_check_membership() does not test whether group exists or not. Querying membership for a nonexistent group will result in ismember being set to 0. The function returns 0 on success or one of the following error codes on failure: [EIO] Communication with openditectoryd(8) failed. [ENOENT] user can not be found. mbr_check_service_membership() is identical to mbr_check_membership() except that ENOENT means no service ACL has been defined. SEE ALSO
odutil(1), setgroups(2), getgroups(2), mbr_uid_to_uuid(3), opendirectoryd(8) Mac OS X November 5, 2011 Mac OS X
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy