Sponsored Content
Top Forums Shell Programming and Scripting sed , awk script for printing matched line before regular expression Post 302900503 by kshitij on Wednesday 7th of May 2014 06:45:58 AM
Old 05-07-2014
Blade sed , awk script for printing matched line before regular expression

hi All ,

I am having a large file with lots of modules as shown below
###############################################

Code:
 module KKK 
kksd 
kskks  
jsn;lsm
jsnlsn;
Ring 
jjsjsj
kskmsm
jjs
endmodule

 module llll 
1kksd11 
k232skks  
j33sn;l55sm
js333nl33sn;
Ring 
jj33sj4sj
k33sk33msm
j33js
endmodule

################################################

I need to match Ring regular expression and script should print corresponding module related to that "Ring" expression ...Ring lies in different modules ...

Output file

Code:
Ring :  module kkkk 
Ring : module lll

#################################

I am using this one liner
Code:
awk '/Ring/ {print  x} {x=$0}' file

but it is priting one line above the Ring expression ...
I need to find out the corresponding module of the Ring where it lies and create a output file

Please help me out

Last edited by Don Cragun; 05-07-2014 at 05:14 PM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

2. Shell Programming and Scripting

sed not printing lines before a regular expression.

Hey, I found a way to print the lines which is just before a regular expression, not including the expression. sed -n '/regexp/{n;p;}' myfile Now I'm looking for a way to print all lines, exept the regular expression and also the line before the same regular expression. Use code tags. (1 Reply)
Discussion started by: Livio
1 Replies

3. Shell Programming and Scripting

AWK script issue for the part regular expression

Hi I am having a file as shown below FILE 1 TXDD00, TXDD01, TXDD02, TXDD03, TXDD04, TXDD05, TXDD06, TXDD07, TXDD08, TXDD09, TXDD10, TXDD11, TXDD12, TXDD13, TXDD14, TXDD15, TXDD16, TXDD17, TXDD18, TXDD19, TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1,... (3 Replies)
Discussion started by: jaita
3 Replies

4. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

5. Shell Programming and Scripting

matched characters - regular expression

Hi, I read the book of <<unix shell programming>>. The regular expression ^\(.\)\1 matches the first character on the line and stores it in register 1. Then the expression matches whatever is stored in the register 1, as specified by the \1. The net effect of this regular expression is to match... (2 Replies)
Discussion started by: jianma
2 Replies

6. Shell Programming and Scripting

How can I get the matched text when using regular expression.

Hello: (exp) : match "exp",the matched text is stored in auto named arrays. How can I get the matched text ? What is the name of the auto named arrays on linux shell ? (4 Replies)
Discussion started by: 915086731
4 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

9. UNIX for Advanced & Expert Users

Add a line after last matched expression

I thought this would be easy to Google, but I am having trouble getting a clean result that I can understand. I simply want to insert the the line: My Network 192.168.1.1 After the last line that begins with ACL localnet (15 Replies)
Discussion started by: glev2005
15 Replies

10. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies
tra(7)							 Miscellaneous Information Manual						    tra(7)

NAME
tra - DETRA 4 Mb/s or 16 Mb/s Token Ring interface SYNOPSIS
config_driver tra Entry in the system configuration file DESCRIPTION
The tra interface is a Token Ring TURBOchannel adapter that can operate at 4 Mb/s or 16 Mb/s. The adapter uses a TMS380 chip to implement the Token Ring protocol. The host's Internet address is specified at boot time with a SIOCSIFADDR ioctl. Also the speed at which the interface should operate can be specified using the SIOCSMACSPEED ioctl. The default speed at which the interface will try and enter the ring is at 16 Mb/s. The other supported speed is 4 Mb/s. ifconfig(8) describes how to set the speed of the interface by using the speed option. The maximum MAC frame size supported by the driver on a 4 Mb/s Token Ring network is 4136 and for a 16 Mb/s network it is 8232. The SIOCRPHYSADDR ioctl can be used to read the physical address of the DETRA adapter. The SIOCADDMULTI and SIOCDELMULTI ioctls can be used to add or delete functional addresses. The SIOCRDCTRS ioctl can be used to read the Token Ring driver counters. The DETRA adapter status and characteristics can also be read through this ioctl by providing one of the following options: Reads the counters Reads the characteristics Reads the RFC 1231 mib entry Reads the RFC 1231 status entry The driver does not support reporting information on the timer statistics as defined in RFC 1239. The argument to this ioctl is a pointer to a counter or status structure, ctrreq, found in <net/if.h>. The structures defining the Token Ring counters and status maintained can be found in <netinet/if_trnstat.h>. The SIOCENABLBACK and SIOCDISABLBACK ioctls can be used to enable and disable the interface loopback mode, respectively. The driver enables internal loopback only. The SIOCIFRESET ioctl can be used to reset the adapter. EXAMPLES
To obtain the physical address of the adapter, use the SIOCRPHYSADDR ioctl as in the following program example: #include <stdio.h> /* standard I/O */ #include <errno.h> /* error numbers */ #include <sys/socket.h> /* socket definitions */ #include <sys/ioctl.h> /* ioctls */ #include <net/if.h> /* generic interface structures */ main() { int s,i; static struct ifdevea devea; /* Get a socket */ s = socket(AF_INET,SOCK_DGRAM,0); if (s < 0) { perror("socket"); exit(1); } strcpy(devea.ifr_name,"tra0"); if (ioctl(s,SIOCRPHYSADDR,&devea) < 0) { perror(&devea.ifr_name[0]); exit(1); } printf("Address is "); for (i = 0; i < 6; i++) printf("%X ", devea.default_pa[i] & 0xff); printf(" "); close(s); } To reset the adapter, use the SIOCIFRESET ioctl as in the following program example: #include <stdio.h> /* standard I/O */ #include <errno.h> /* error numbers */ #include <sys/socket.h> /* socket definitions */ #include <sys/ioctl.h> /* ioctls */ #include <net/if.h> /* generic interface structures */ main() { int s; struct ifreq data; /* Get a socket */ s = socket(AF_INET,SOCK_DGRAM,0); if (s < 0) { perror("socket"); exit(1); } strcpy(data.ifr_name,"tra0"); if (ioctl(s,SIOCIFRESET,&data) < 0) { perror("SIOCIFRESET:"); exit(1); } close(s); } ERRORS
Diagnostic messages contain information provided by the tra driver and the adapter. The following messages contain information about the adapter's state, and are printed on the console. Each message begins with the adapter identification, including the number of the adapter: The driver received an adapter check interrupt. The reason for the interrupt is displayed. The driver could not get an aligned address for the System Status Block (SSB). (See Texas Instruments, TMS380 Second-Generation Token Ring User's Guide for an explanation of SSB.) The Bring Up Diagnostics (BUD) failed. The value of the command/status register and the reason for the failure are displayed. The driver received an unknown interrupt. An error while trying to write out the initialization block to the TMS380 Token Ring chip. The value of the command/status register is displayed in hexadecimal. The MAC_CLOSE command returned an unknown status to the driver. A request to close the MAC was previously issued to the adapter. A request to open the MAC was previously issued to the adapter. The command to open the MAC was rejected. The reason is displayed. The driver opened the adapter into the ring at the speed indicated. Only two speeds are supported - 4 Mb/s and 16 Mb/s. If either message is displayed, reset the adapter by issuing the following commands: % ifconfig tra0 down % ifconfig tra0 up If the message persists, an error is occurring while transmitting and receiving packets. You will need to investigate the error. The status of the ring. The driver has taken the adapter off the ring. A timeout occurred while waiting for the MAC_READ_ERROR_LOG command to complete. A timeout occurred while trying to close the MAC; the interface is down. A timeout occurred while waiting for the MAC_OPEN command to complete. RELATED INFORMATION
netstat(1), ifconfig(8), srconfig(8) Network Programmer's Guide delim off tra(7)
All times are GMT -4. The time now is 10:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy