Print text between delimiters IF it contains a certain term...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print text between delimiters IF it contains a certain term...
# 8  
Old 09-07-2011
It depends, consider that that --- is considered a single dash: -.
It's not regex vs string, it's multi-character/regex vs. single character.
This User Gave Thanks to radoulov For This Post:
# 9  
Old 09-07-2011
If im not wrong, shall we say that all awks support multi-character in RS..?
# 10  
Old 09-07-2011
Consider the following:

Code:
% awk --version | head -1;printf '%s\n' a--b-c | awk 'END { print NR } 1'  RS=--
GNU Awk 4.0.0
a
b-c

2

Code:
$ uname -sr; printf '%s\n' a--b-c | nawk 'END { print NR } 1' RS=--
SunOS 5.8
a

b
c

4


Code:
$ uname -sr; printf '%s\n' a--b-c | /usr/xpg4/bin/awk 'END { print NR } 1' RS=--
SunOS 5.8
a

b
c

4

This User Gave Thanks to radoulov For This Post:
# 11  
Old 09-07-2011
Quote:
Originally Posted by michaelrozar17
If im not wrong, shall we say that all awks support multi-character in RS..?
No!

Man nawk on Sun OS:

Quote:
RS The first character of the string value of RS is the
input record separator; a newline character by
default. If RS contains more than one character, the
results are unspecified. If RS is null, then records
are separated by sequences of one or more blank lines:
leading or trailing blank lines do not produce empty
records at the beginning or end of input, and the
field separator is always newline, no matter what the
value of FS.
# 12  
Old 09-07-2011
mawk seems to support regex as RS too:

Code:
% uname -sr; printf '%s\n' a--b-c | mawk 'END { print NR } 1' RS=--
Linux 2.6.38-11-generic
a
b-c

2
% uname -sr; printf '%s\n' a--b-c | mawk 'END { print NR } 1' RS=-+
Linux 2.6.38-11-generic
a
b
c

3

From man mawk on Ubuntu:

Quote:
RS input record separator, initially = "\n".
[...]
RS = " " is not special.
The documentation states:

Code:
mawk splits files into records by the same algorithm, but with the slight difference that RS is really a  termina-
       tor instead of a separator.  (ORS is really a terminator too).

              E.g., if FS = ":+" and $0 = "a::b:" , then NF = 3 and $1 = "a", $2 = "b" and $3 = "", but if "a::b:" is the
              contents of an input file and RS = ":+", then there are two records "a" and "b".


Last edited by radoulov; 09-07-2011 at 11:13 AM..
# 13  
Old 09-09-2011
Thanks radoulov for your kind explanation..
# 14  
Old 09-09-2011
You're very welcome!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

find & Replace text using two non-unique delimiters.

I can find and replace text when the delimiters are unique. What I cannot do is replace text using two NON-unique delimiters: Ex., "This html code <text blah >contains <garbage blah blah >. All tags must go,<text > but some must be replaced with <garbage blah blah > without erasing other... (5 Replies)
Discussion started by: bedtime
5 Replies

2. Shell Programming and Scripting

How to put delimiters in text files after fix characters?

Hi , i have a text file in which i want to put delimiters after certain characters ( fix),. like put a delimiter (any like ,) after 1-3 character than 4 than 5 than 6-17 ..... files looks like this (original)... (8 Replies)
Discussion started by: anamdev
8 Replies

3. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

4. Shell Programming and Scripting

Print text it contains a certain term...

Hello, I need to extract execution error on a log file. I am on Linux, but I can only use bash or ksh. As a sample of what I'm needing, here is some data; ***** L1 FILE VAX_ASP1_SATx_E_IM20101017035246 - CPU TIME 2011-04-29T09:57:57 ***** GMT_PRODUCT_CREATION_TIME = 2011-04-29T09:57:57... (6 Replies)
Discussion started by: Aswex
6 Replies

5. Shell Programming and Scripting

Order text by delimiters

I try order the content from file by delimiters. This is the text: interface Loopback0 description !!!RID RR_SLT ip address 172.31.128.19 255.255.255.255 interface GigabitEthernet0 description !!!P_SLT GI0/0/9 ip address 172.31.130.246 255.255.255.252 and the result that I need... (11 Replies)
Discussion started by: bobbasystem
11 Replies

6. AIX

Print text between two delimiters

Hi, Can somebody help me with the below situation, Input File, ======== 2007_08_07_IA-0100-014_(MONTHLY).PDF 2007_08_07_IA-0100-031_(QUARTERLY)(RERUN).PDF 2008-02-28_KR-1022-003_(MONTH)(RERUN)(REC1).CSV Required output, ============ MONTHLY QUARTERLY MONTH ... (15 Replies)
Discussion started by: sravicha
15 Replies

7. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

8. UNIX for Advanced & Expert Users

extract text b/w two delimiters

I have an input file which looks like " @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql... (6 Replies)
Discussion started by: dowsed4u8
6 Replies

9. Shell Programming and Scripting

Search term and output term in desired field

Hi All, I have an input_file below and i would like to use Perl to search for the term "aaa" and output the 3rd term in the same row as "aaa".For Example, i want to search for the term "ddd" and would want the code to ouput the 3rd term in the same row which is "fff". Can somebody help ? ... (28 Replies)
Discussion started by: Raynon
28 Replies

10. Programming

Create a Term & Run chars on this Term

hi floks ! i'd like to know how can i transmete a character or a string from my source code to a term and make it interpret or un by the shell wich is running in my term. I'd like to create a Term from my code (and get its file descriptor) and then transmete each char typed on the keyboard to... (1 Reply)
Discussion started by: the_tical
1 Replies
Login or Register to Ask a Question