search replace regex question

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support search replace regex question
# 8  
Old 12-12-2011
@lawstudent: Is this what you're looking for?

inputfile.txt:
Code:
#### (eg. 1764 or 1964)
#### (eg. 1864 or 2064)
#### (eg. 1964 or 1764)
#### (eg. (2764) or (1164))

Code:
$ perl -ne 's/ ([0-9]{4})/ \($1\)/g; print $_' inputfile.txt
#### (eg. (1764) or (1964))
#### (eg. (1864) or (2064))
#### (eg. (1964) or (1764))
#### (eg. (2764) or (1164))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help to use regex to do search and replace. Don't know how to and can't figure out how :(

Hi, Below is an excerpt from a 20000+ lines and I want to do a search and replace of a specific string but I don't know how and I can't figure out how to. Can't find an example from Google or anywhere to do what I am wanting to do. A 2018-11-21 08:42:17 TEST_TEST 2018-11-21... (9 Replies)
Discussion started by: newbie_01
9 Replies

2. Shell Programming and Scripting

Search Replace Specific Column using RegEx

Have Pipe Delimited File: > BRYAN BAKER|4/4/2015|518 VIRGINIA AVE|TEST > JOE BAXTER|3/30/2015|2233 MockingBird RD|ROW2On 3rd column where the address is located, I want to add a space after every numeric value - basically doing a "s//&\ / ": > BRYAN BAKER|4/4/2015|5 1 8 VIRGINIA AVE|TEST > JOE... (5 Replies)
Discussion started by: svn
5 Replies

3. Shell Programming and Scripting

Multi line regex for search and replace

I have text file like below: a.txt Server=abc Run=1 Time=120.123 Tables=10 Sessions=16 Time=380.123 Version=1.1 Jobs=5 Server=abc Run=2 Time=160.123 Tables=15 Sessions=16 Time=400.258 Version=2.0 (1 Reply)
Discussion started by: sol_nov
1 Replies

4. Shell Programming and Scripting

Regex - search and replace

I have file which contains data in the following format all in a single line: BDW_PUBLN_ID DECIMAL(18:0) NOT NULL PRIMARY INDEX ARGO_ACCT_DEP_PI ( OFC_ID ,CSHBX_ID ,TRXN_SEQ_NUM ,PROCG_DT ) PARTITION BY RANGE_N(PROCG_DT BETWEEN DATE '2012-03-01' AND DATE '2014-12-31' EACH INTERVAL '1' MONTH );... (4 Replies)
Discussion started by: ysvsr1
4 Replies

5. Shell Programming and Scripting

Search and replace question

Hi all, I am trying to modify an xml file and I wanted to search and replace using the sed command but here is my issue. I want to search and replace maximumHeapSize="512" and replace it with maximumHeapSize="768" but I have multiple files with different values so I can't search for... (2 Replies)
Discussion started by: reyes99
2 Replies

6. Shell Programming and Scripting

Perl:Regex for Search and Replace that has a flexible match

Hi, I'm trying to match the front and back of a sequence. It works when there is an exact match (obviously), but I need the regex to be more flexible. When we get strings of nucleotides sometimes their prefixes and suffixes aren't exact matches. Sometimes there will be an extra letter and... (2 Replies)
Discussion started by: jdilts
2 Replies

7. Shell Programming and Scripting

Regex:search/replace but not for escaped character

Hi Input: - -- --- ---- aa-bb-cc aa--bb--cc aa---bb---cc aa----bb----cc Output: . - -. -- aa.bb.cc (7 Replies)
Discussion started by: chitech
7 Replies

8. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

9. Shell Programming and Scripting

Search & Replace question

Hi all, I have one question that hopefully isn't too complicated for the more advanced users here. In one of the Solaris KSH scripts I'm working on, is it possible to script the following: - If there "is" an empty blank line "at the end" of /tmp/text.txt, then remove only that one empty... (3 Replies)
Discussion started by: chatguy
3 Replies

10. UNIX for Dummies Questions & Answers

search and replace one more question

Hi, I have a file that contains the following contents: 14:05 apple orange123 456mango 16:45 banana I wanted to replace ONLY the "14:05 " and "16:45" with nothing and trying to use the following syntax sed -e 's/*//g' -e 's/^: //g' my_file > new_temp cat new_temp apple orange... (2 Replies)
Discussion started by: ghazi
2 Replies
Login or Register to Ask a Question
AUSEARCH_ADD_ITEM(3)						  Linux Audit API					      AUSEARCH_ADD_ITEM(3)

NAME
ausearch_add_item - build up search rule SYNOPSIS
#include <auparse.h> int ausearch_add_item(auparse_state_t *au, const char *field, const char *op, const char *value, ausearch_rule_t how); DESCRIPTION
ausearch_add_item adds one search condition to the current audit search expression. The search conditions can then be used to scan logs, files, or buffers for something of interest. The field value is the field name that the value will be checked for. The op variable describes what kind of check is to be done. Legal op values are: exists just check that a field name exists = locate the field name and check that the value associated with it is equal to the value given in this rule. != locate the field name and check that the value associated with it is NOT equal to the value given in this rule. The value parameter is compared to the uninterpreted field value. The how value determines how this search condition will affect the existing search expression if one is already defined. The possible val- ues are: AUSEARCH_RULE_CLEAR Clear the current search expression, if any, and use only this search condition. AUSEARCH_RULE_OR If a search expression E is already configured, replace it by (E || this_search_condition). AUSEARCH_RULE_AND If a search expression E is already configured, replace it by (E && this_search_condition). RETURN VALUE
Returns -1 if an error occurs; otherwise, 0 for success. SEE ALSO
ausearch_add_expression(3), ausearch_add_interpreted_item(3), ausearch_add_timestamp_item(3), ausearch_add_regex(3), ausearch_set_stop(3), ausearch_clear(3), ausearch_next_event(3), ausearch-expression(5). AUTHOR
Steve Grubb Red Hat Nov 2007 AUSEARCH_ADD_ITEM(3)