Regexp to separated rows by "asterisks-new line" in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regexp to separated rows by "asterisks-new line" in awk
# 1  
Old 03-18-2013
Regexp to separated rows by "asterisks-new line" in awk

Hello to all,

I have the text file below, how would be the REGEXP to set the RS to separate registers by asterisks-newline-asterisks (highlighted in red)
and FS as the default, in order that the fourth field ($4) always be the number after REG (in blue)?

I'm trying with code below, but is not working:
Code:
 awk 'BEGIN {RS = "*[^\n]*\n"} {print $4}' file.txt

Sample file:
Code:
*************************Start of REG 1*************************
Start_addr:0x1c
REG_TYPE: MORecord

recordType: 00
served: 18345380
cMLegInformation:
{
        {Number: (A1)100273
}
systemType: 02(Decimal)
recordNumber: 2011795345(Decimal)
**************************End of REG 1**************************

*************************Start of REG 2*************************
Start_addr:0x1e7
REG_TYPE: OutGatewayRecord

recordType: 04
lastmcn: 07F820
**************************End of REG 2**************************

*************************Start of REG 3*************************
Start_addr:0x2e2
REG_TYPE: Record

recordType: 02
served: 20942254
supplServicesUsed:
{
        {SSCode:11 ssTime:2013-03-05 06:52:20 - 0600}
}
**************************End of REG 3**************************

Thanks in advance.

Last edited by Ophiuchus; 03-18-2013 at 10:41 PM..
# 2  
Old 03-18-2013
maybe something like:
Code:
awk '/Start of REG/{FS="[* ]+" ; $0=$0; record=$5; print record}' file.txt

# 3  
Old 03-18-2013
Hello rdrtx1,

Thank you for your help, it works, but I need to have all values between "..**Start of REG N**.." and "..**End of REG N**.."
in a unique row, because I want to have each value as a field.

For this reason I looking for how to set a working Regexp as a row separator RS.

Thanks in advance.
# 4  
Old 03-19-2013
try:
Code:
awk '$1=$1 {++record; print record":"$0}' RS="[*]+[^\n]+[*]+" in.txt

Each word between asterisk lines are $1, $2, etc.
# 5  
Old 03-19-2013
Hello rdrtx1,

This regexp works!!

Thank youu!

Regards
# 6  
Old 03-19-2013
Note: only in gawk and mawk can RS contain a regex. Regular awk only supports a single character.

Last edited by Scrutinizer; 03-19-2013 at 02:51 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

awk :help to parse a file to change to separated by colon ":"

Hi experts , I am trying to get the below output: file : 0/6/4/1 0x0019503C2E26 5 UP lan5 snap5 1 ETHER Yes 224 0/6/4/0 0x0019503C2E25 6 UP lan6 snap6 2 ETHER Yes 224 0/2/1/0 0x0019503E6900 0 UP lan0 snap0 3 ETHER Yes 224... (8 Replies)
Discussion started by: rveri
8 Replies

4. Shell Programming and Scripting

AWK for multiple line records RS="^" FS="#"

I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)... Sample record is: ^-60#ORA-00060: deadlock detected while waiting for resource ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. Shell Programming and Scripting

How to cut a file using " ", but fields can be separated with more than one " "

Hello, let's say I have a text file: word11 word12 word13 word21 word22 word23 word31 word32 word33 and I want to put the second field of each line into a list: set list = `cut -d" " -f2 ${1}` and I use space (" ") as a delimiter, only that there's a catch: there can be more than... (12 Replies)
Discussion started by: shira
12 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question