Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to specify beginning-of-line/end-of-line characters inside a regex range Post 302659201 by gary_w on Wednesday 20th of June 2012 01:31:58 PM
Old 06-20-2012
I believe some versions of sed allow a logical or. Mine does not. Try this:

Code:
sed 's/^test\||test/found_it/g' filename

If portability is a concern, you might want to stick with something like this:
Code:
sed 's/|test/FOUND/g;s/^test/FOUND/g' filename

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert two strings at the beginning and at the end of each line of a file

Hi, excuse me for my poor english. My problem is that: I have a File i want to add to each line of that file two strings: one at the beginning of the line, one at the ending. string1="abcd" string2="efgh" i want $string1 content $string2 for each line. Is that possible? (3 Replies)
Discussion started by: Linux-fueled
3 Replies

2. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

3. Shell Programming and Scripting

adding characters end of line where line begins with..

Hi all, using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg a,b,c,......., r,s,t,........, a,b,c,......., all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the... (6 Replies)
Discussion started by: satnamx
6 Replies

4. UNIX for Dummies Questions & Answers

Regex for beginning of line until a comma

What is a regex for "the dalai lama, his holiness the" that would just grab "the dalai lama" and one that would just grab "his holiness the"? Both should exclude the comma.. I was trying '^.*' and many variants with no luck. (6 Replies)
Discussion started by: glev2005
6 Replies

5. Shell Programming and Scripting

trying to add text to beginning and end of each line

Well here goes: I tried to write a batch file that adds a specific fixed text to each line of an already existing text file. for the adding text infront of each line I tried this: for /F "delims=" %%j in (list.txt) do echo.STARTTEXT\%%j >> list.txt for adding text after each line I... (0 Replies)
Discussion started by: pasc
0 Replies

6. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

7. UNIX for Dummies Questions & Answers

sed - Add a variable line to the end of a block beginning with a regex

Hi, Need some help with sed. I have a file that has sections : e.g. a=blah b=blah d=blah e=blah There's many sections in the file. (1 Reply)
Discussion started by: andyatit
1 Replies

8. Shell Programming and Scripting

[Solved] Inserting a line beginning with regex

I have been trying to insert a line after a regex but I can't do it. Here is the code I am using: cat saved_doc SET type = type1 SET type = STORE = y /vol/san_e1 /vol/san_5 /vol/san_e9 /vol/san_e11 /vol/san_e12 /vol/san_e13 /vol/san_e14 /vol/san_e16 /vol/san_e17 /vol/san_e18... (4 Replies)
Discussion started by: newbie2010
4 Replies

9. Shell Programming and Scripting

Add new line at beginning and end of a file

Hi, I have a specific requirement to add text at the beginning and end of a plain text file. I tried to use "sed" with '1i' and '$a' flags but these required two separate "sed" commands separated with "|". I am looking for some command/option to join these two in single command parameter. ... (6 Replies)
Discussion started by: bhupinder08
6 Replies

10. UNIX for Beginners Questions & Answers

Inserting n characters to beginning of line if match

I would like to insert n number of characters at the beginning of each line that starts with a given character. If possible, I would be most appreciative for a sed or awk solution. Given the data below, I would like to be able to insert either 125 spaces or 125 "-" at the beginning of every line... (6 Replies)
Discussion started by: jvoot
6 Replies
regex.h(3HEAD)							      Headers							    regex.h(3HEAD)

NAME
regex.h, regex - regular expression matching types SYNOPSIS
#include <regex.h> DESCRIPTION
The <regex.h> header defines the structures and symbolic constants used by the regcomp(), regexec(), regerror(), and regfree() functions. See regcomp(3C). The structure type regex_t contains the following member: size_t re_nsub number of parenthesized subexpressions The type size_t is defined as described in <sys/types.h>. See types.h(3HEAD). The type regoff_t is defined as a signed integer type that can hold the largest value that can be stored in either a type off_t or type ssize_t. The structure type regmatch_t contains the following members: regoff_t rm_so byte offset from start of string to start of substring regoff_t rm_eo byte offset from start of string of the first character after the end of substring Values for the cflags parameter to the regcomp function are as follows: REG_EXTENDED use extended regular expressions REG_ICASE ignore case in match REG_NOSUB report only success or fail in regexec() REG_NEWLINE change the handling of NEWLINE character Values for the eflags parameter to the regexec() function are as follows: REG_NOTBOL The circumflex character (^), when taken as a special character, does not match the beginning of string. REG_NOTEOL The dollar sign ($), when taken as a special character, does not match the end of string. The following constants are defined as error return values: REG_NOMATCH regexec() failed to match. REG_BADPAT Invalid regular expression. REG_ECOLLATE Invalid collating element referenced. REG_ECTYPE Invalid character class type referenced. REG_EESCAPE Trailing '' in pattern. REG_ESUBREG Number in fIdigit invalid or in error. REG_EBRACK "[]" imbalance. REG_EPAREN "()" or "()" imbalance. REG_EBRACE "" imbalance. REG_BADBR Content of "" invalid: not a number, number too large, more than two numbers, first larger than second. REG_ERANGE Invalid endpoint in range expression. REG_ESPACE Out of memory. REG_BADRPT '?', '*', or '+' not preceded by valid regular expression. REG_ENOSYS Reserved. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
regcomp(3C), types.h(3HEAD), attributes(5), standards(5) SunOS 5.11 9 Sep 2004 regex.h(3HEAD)
All times are GMT -4. The time now is 03:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy