Sponsored Content
Full Discussion: Cut -d Question
Top Forums Shell Programming and Scripting Cut -d Question Post 302111185 by Janus on Monday 19th of March 2007 10:54:41 PM
Old 03-19-2007
Quote:
Originally Posted by Ygor
Search:
Code:
\(     start of first bracketed pattern
.*     any number of characters
\)     end of first bracketed pattern
==-=-  literal
.*     any number of characters
\(     start of second bracketed pattern
\.pdf  literal ("." is escaped to prevent its special meaning)
\)     end of second bracketed pattern

Replacement:
Code:
\1     first bracketed pattern
\2     second bracketed pattern

Thank you, I see now how it all fits together. Seeing the actual meaning behind what each piece is doing helps out quite a bit! As stated in the replies above, .pdf isn't necessarily the only file extension this would have to look for. I made a slight change to it and it seems to work:

sed 's/\(.*\)==-=-.*\(\...\)/\1\2/'

I took pdf and replaced it with ..., the only question is, what if there is a greater number than 3 for the file extension? I don't think ... will work then, since it's going for literally 3 characters for that second part. What would be the correct expression to use to say "Any amount of character" and not just 3? Thanks again, both of ye for your input and help!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cut question

#!/bin/bash echo "UserName PID Command" ps -ef > ps.temp grep '^\{2,3\}\{4\}' ps.temp > ps.temp2 cut -f1,2,8 ps.temp2 rm ps.temp* I am having some problems with the cut command. I only want to display the UID (field 1), PID(field 2), and Command(field 8). Right now the whole ps -ef... (5 Replies)
Discussion started by: knc9233
5 Replies

2. Shell Programming and Scripting

SED and Cut question

I am trying to cut and delete using sed and redirect back into the file. This is not working write. When testing the script, it hangs. Any idea what I am doing wrong here. ################ Reads the input file to cut volumes for returns and CUT_ERVTAPE_FILE() { echo "working on cut... (2 Replies)
Discussion started by: gzs553
2 Replies

3. Shell Programming and Scripting

sort / cut question

Hi All, I have a small problem, hope you can help me out here. I have a file that contains the same format of lines in 99% of the cases. 906516 XYZ.NNN V 0000 20070711164648 userID1 userID2 hostname 20070711164641 There are unfortunately several lines with these... (5 Replies)
Discussion started by: BearCheese
5 Replies

4. Shell Programming and Scripting

The cut command. Really simple question!

hi, sorry for asking what I am sure is a really easy question, I am wanting to cut the users real name from the output of 'finger'. $ cut -f2-3 filename is in my script but it only seems to cut the first line. I need to cut the 2nd and 3rd word from each line and store them in variables... (1 Reply)
Discussion started by: rorey_breaker
1 Replies

5. UNIX for Dummies Questions & Answers

Cut Question

Hi, I have created a variable abc within my script which can have values as follows abc = Ram,Iam or it can be abc = Uam or it can be abc = Sam,Tam,Pam Basically it can have a max of 3 values , seperated by comma. I want to assign these 3 values to 3 different variables In case of... (2 Replies)
Discussion started by: samit_9999
2 Replies

6. UNIX for Dummies Questions & Answers

cut awk dummy question :)

how to make cut and awk treat "a b" as a single column rather then two separate columns "a and b"? how to remove " symbol from "a b" so there is only a b? Please help Regards Karol (14 Replies)
Discussion started by: sopel39
14 Replies

7. UNIX for Dummies Questions & Answers

Question on the cut command

Suppose one has a file consisting of more than 2 columns and one has to extract a few columns from this file and swap some columns at the same time. Example: extract column 1, 2 and 4 from a file foo.csv and place them in the order 2, 4 and 1 into file foo.txt. I would be inclined to do this: cut... (4 Replies)
Discussion started by: figaro
4 Replies

8. Shell Programming and Scripting

Simple Cut Question

I've got a file that contains a large list of links in this type of style: 'home_dir\2009\09\01\file.html' I'd like to cut off all of the characters left of 'file.html'. I tried: cat file.txt | cut -d\ -f4 but it told me that I had an invalid delimiter. So I tried: cat... (5 Replies)
Discussion started by: Rally_Point
5 Replies

9. Shell Programming and Scripting

A question on cut

hi, I used cut to get the I have a file f1 with content: 101.2 ms RTT from 3WHS 95.2 ms RTT from 3WHS 97.3 ms RTT from 3WHS 97.4 ms RTT from 3WHS 122.2 ms RTT from 3WHS 103.5 ms RTT from... (2 Replies)
Discussion started by: esolve
2 Replies

10. UNIX for Dummies Questions & Answers

Question on cut

Korn Shell I have a file whose values are delimited using colon ( : ) $ cat test.txt hello:myde:temp:stiker $ cut -d: -f2,4 test.txt myde:stikerI want field 2 and field 4 to be returned but separated by a hyphen. The output should look like myde-stiker How can do this ? (without awk... (11 Replies)
Discussion started by: kraljic
11 Replies
uwildmat(3)						    InterNetNews Documentation						       uwildmat(3)

NAME
uwildmat, uwildmat_simple, uwildmat_poison - Perform wildmat matching SYNOPSIS
#include <inn/libinn.h> bool uwildmat(const char *text, const char *pattern); bool uwildmat_simple(const char *text, const char *pattern); enum uwildmat uwildmat_poison(const char *text, const char *pattern); DESCRIPTION
uwildmat compares text against the wildmat expression pattern, returning true if and only if the expression matches the text. "@" has no special meaning in pattern when passed to uwildmat. Both text and pattern are assumed to be in the UTF-8 character encoding, although malformed UTF-8 sequences are treated in a way that attempts to be mostly compatible with single-octet character sets like ISO 8859-1. (In other words, if you try to match ISO 8859-1 text with these routines everything should work as expected unless the ISO 8859-1 text contains valid UTF-8 sequences, which thankfully is somewhat rare.) uwildmat_simple is identical to uwildmat except that neither "!" nor "," have any special meaning and pattern is always treated as a single pattern. This function exists solely to support legacy interfaces like NNTP's XPAT command, and should be avoided when implementing new features. uwildmat_poison works similarly to uwildmat, except that "@" as the first character of one of the patterns in the expression (see below) "poisons" the match if it matches. uwildmat_poison returns UWILDMAT_MATCH if the expression matches the text, UWILDMAT_FAIL if it doesn't, and UWILDMAT_POISON if the expression doesn't match because a poisoned pattern matched the text. These enumeration constants are defined in the inn/libinn.h header. WILDMAT EXPRESSIONS
A wildmat expression follows rules similar to those of shell filename wildcards but with some additions and changes. A wildmat expression is composed of one or more wildmat patterns separated by commas. Each character in the wildmat pattern matches a literal occurrence of that same character in the text, with the exception of the following metacharacters: ? Matches any single character (including a single UTF-8 multibyte character, so "?" can match more than one byte). * Matches any sequence of zero or more characters. Turns off any special meaning of the following character; the following character will match itself in the text. "" will escape any character, including another backslash or a comma that otherwise would separate a pattern from the next pattern in an expression. Note that "" is not special inside a character range (no metacharacters are). [...] A character set, which matches any single character that falls within that set. The presence of a character between the brackets adds that character to the set; for example, "[amv]" specifies the set containing the characters "a", "m", and "v". A range of characters may be specified using "-"; for example, "[0-5abc]" is equivalent to "[012345abc]". The order of characters is as defined in the UTF-8 character set, and if the start character of such a range falls after the ending character of the range in that ranking the results of attempting a match with that pattern are undefined. In order to include a literal "]" character in the set, it must be the first character of the set (possibly following "^"); for example, "[]a]" matches either "]" or "a". To include a literal "-" character in the set, it must be either the first or the last character of the set. Backslashes have no special meaning inside a character set, nor do any other of the wildmat metacharacters. [^...] A negated character set. Follows the same rules as a character set above, but matches any character not contained in the set. So, for example, "[^]-]" matches any character except "]" and "-". In addition, "!" (and possibly "@") have special meaning as the first character of a pattern; see below. When matching a wildmat expression against some text, each comma-separated pattern is matched in order from left to right. In order to match, the pattern must match the whole text; in regular expression terminology, it's implicitly anchored at both the beginning and the end. For example, the pattern "a" matches only the text "a"; it doesn't match "ab" or "ba" or even "aa". If none of the patterns match, the whole expression doesn't match. Otherwise, whether the expression matches is determined entirely by the rightmost matching pattern; the expression matches the text if and only if the rightmost matching pattern is not negated. For example, consider the text "news.misc". The expression "*" matches this text, of course, as does "comp.*,news.*" (because the second pattern matches). "news.*,!news.misc" does not match this text because both patterns match, meaning that the rightmost takes precedence, and the rightmost matching pattern is negated. "news.*,!news.misc,*.misc" does match this text, since the rightmost matching pattern is not negated. Note that the expression "!news.misc" can't match anything. Either the pattern doesn't match, in which case no patterns match and the expression doesn't match, or the pattern does match, in which case because it's negated the expression doesn't match. "*,!news.misc", on the other hand, is a useful pattern that matches anything except "news.misc". "!" has significance only as the first character of a pattern; anywhere else in the pattern, it matches a literal "!" in the text like any other non-metacharacter. If the uwildmat_poison interface is used, then "@" behaves the same as "!" except that if an expression fails to match because the rightmost matching pattern began with "@", UWILDMAT_POISON is returned instead of UWILDMAT_FAIL. If the uwildmat_simple interface is used, the matching rules are the same as above except that none of "!", "@", or "," have any special meaning at all and only match those literal characters. BUGS
All of these functions internally convert the passed arguments to const unsigned char pointers. The only reason why they take regular char pointers instead of unsigned char is for the convenience of INN and other callers that may not be using unsigned char everywhere they should. In a future revision, the public interface should be changed to just take unsigned char pointers. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> in 1986, and posted to Usenet several times since then, most notably in comp.sources.misc in March, 1991. Lars Mathiesen <thorinn@diku.dk> enhanced the multi-asterisk failure mode in early 1991. Rich and Lars increased the efficiency of star patterns and reposted it to comp.sources.misc in April, 1991. Robert Elz <kre@munnari.oz.au> added minus sign and close bracket handling in June, 1991. Russ Allbery <rra@stanford.edu> added support for comma-separated patterns and the "!" and "@" metacharacters to the core wildmat routines in July, 2000. He also added support for UTF-8 characters, changed the default behavior to assume that both the text and the pattern are in UTF-8, and largely rewrote this documentation to expand and clarify the description of how a wildmat expression matches. Please note that the interfaces to these functions are named uwildmat and the like rather than wildmat to distinguish them from the wildmat function provided by Rich $alz's original implementation. While this code is heavily based on Rich's original code, it has substantial differences, including the extension to support UTF-8 characters, and has noticable functionality changes. Any bugs present in it aren't Rich's fault. $Id: uwildmat.pod 9074 2010-05-31 19:01:32Z iulius $ SEE ALSO
grep(1), fnmatch(3), regex(3), regexp(3). INN 2.5.3 2011-06-10 uwildmat(3)
All times are GMT -4. The time now is 04:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy