Sponsored Content
Top Forums Shell Programming and Scripting Script using Sed :Search all patterns & after the last Patter, insert a newLine with Comma Sep Value Post 302679687 by Vryali on Tuesday 31st of July 2012 11:59:46 AM
Old 07-31-2012
Test file:

Code:
$ cat test
paul, Paul Smith, Stevn Smiley, REQ000001, ARS (11)
sam, Sam Martin, Stevn Smiley, REQ000001, ARS (11)
mike, Mike Conway, Stevn Smiley, REQ000001, ARS (11)
mike, Mike Conway, Stevn Smiley, REQ000001, ARS (12)

Results:
Code:
sed "$(awk -F',' '$5 ~ /.*ARS\ \(11\)/ {print NR}' test | tail -1)aTest String of text" test
paul, Paul Smith, Stevn Smiley, REQ000001, ARS (11)
sam, Sam Martin, Stevn Smiley, REQ000001, ARS (11)
mike, Mike Conway, Stevn Smiley, REQ000001, ARS (11)
Test String of text
mike, Mike Conway, Stevn Smiley, REQ000001, ARS (12)

Used awk to get the line numbers of all the regex, then just grabbed the last one and threw it to sed in append mode.
This User Gave Thanks to Vryali For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need to get the last word in comma sep line

I have a file with aaa,bbb,ccc,dddd,eee,xyz aaa,bbb,ccc,dddd,eee,xyz,12345,rty aaa,bbb,ccc,dddd,eee,xyz,12345,rty,tsrt 1. line columns are not fixed 2. all words are seperated by comma what i want is always the string after last comma. regards, Senthil... (9 Replies)
Discussion started by: senthilk615
9 Replies

2. Shell Programming and Scripting

Awk Script: Nested search using different patter

Hi Friends. Please have a look at dummy file. I need to extract from this file: 1. Counts of event= 2. the 2nd coulmn is unique call id of this transaction. Based on that, i have to search for txstatus= . Note: Values of event, calltype and txstatus can be anything. I want to print... (1 Reply)
Discussion started by: itsmesanju
1 Replies

3. Shell Programming and Scripting

sed search alternately for patterns

hi all, I am trying to do search on a gzip file. The file has <pattern1> Data.. <pattern2> data <pattern1> data <patter2> I want to print each pattern 1 and the corrresponding pattern2. If pattern 2 fails to appear and pattern 1 appears, I do not want to print pattern1 and... (3 Replies)
Discussion started by: baskar123
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

sed insert text without newline

Hi, I use sed to insert text at beginning of a file. But sed inserts a newline after my text that I do not need. For example, I want to insert "foo" at the beginning of my file: > cat myfile This is first line. > sed -i '1i\foo' myfile > cat myfile foo This is first line. ... (5 Replies)
Discussion started by: tdw
5 Replies

6. Shell Programming and Scripting

awk: Multiple search patterns & print in an one liner

I would like to print result of multiple search pattern invoked from an one liner. The code looks like this but won't work gawk -F '{{if ($0 ~ /pattern1/) pat1=$1 && if ($0 ~ /pattern2/) pat2=$2} ; print pat1, pat2}' Can anybody help getting the right code? (10 Replies)
Discussion started by: sdf
10 Replies

7. Shell Programming and Scripting

help with tar & zip only last months(say,Sep) files

Need to 1. archive all the files in a directory from the previous month into a tar/gz file, ignoring all already archived 'tar.gz' files 2. Check created .tar.gz file isnt corrupted and has all the required files in it. and then remove the original files. I am using a function to get the... (1 Reply)
Discussion started by: Prev
1 Replies

8. Shell Programming and Scripting

String search between patterns using sed

Hi, I am trying to find a way to get sed/awk/grep to help me find a string in a log file that exists between two datestamps and then print the preceding datestamp up to the next datestamp. Here is an example of my logfile: +++ 2013/03/28 17:01:37.085 SIGNALING HIGH ACTIVE Failure Response... (5 Replies)
Discussion started by: raytx
5 Replies

9. Shell Programming and Scripting

How to replace NewLine with comma using sed?

Hi , I have a huge file with following records and I want to replace the last comma with ',NULL'. I try using SED but could not create a correct script . In my opinion I need a script which can convert ,/n with ,NULL/n 1,CHANGE_MEMBER,2010-12-28 00:05:00, 2,CHANGE_MEMBER,2012-09-02... (8 Replies)
Discussion started by: Ajaypal
8 Replies

10. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies
tran_init_pkt(9E)						Driver Entry Points						 tran_init_pkt(9E)

NAME
tran_init_pkt, tran_destroy_pkt - SCSI HBA packet preparation and deallocation SYNOPSIS
#include <sys/scsi/scsi.h> struct scsi_pkt *prefixtran_init_pkt(structscsi_address *ap, struct scsi_pkt *pkt, struct buf *bp, int cmdlen, int statuslen, int tgtlen, int flags, int (*callback, caddr_t),caddr_t arg); void prefixtran_destroy_pkt(struct scsi_address *ap, struct scsi_pkt *pkt); INTERFACE LEVEL
Solaris architecture specific (Solaris DDI). PARAMETERS
ap Pointer to a scsi_address(9S) structure. pkt Pointer to a scsi_pkt(9S) structure allocated in an earlier call, or NULL. bp Pointer to a buf(9S) structure if DMA resources are to be allocated for the pkt, or NULL. cmdlen The required length for the SCSI command descriptor block (CDB) in bytes. statuslen The required length for the SCSI status completion block (SCB) in bytes. tgtlen The length of the packet private area within the scsi_pkt to be allocated on behalf of the SCSI target driver. flags Flags for creating the packet. callback Pointer to either NULL_FUNC or SLEEP_FUNC. arg Always NULL. DESCRIPTION
The tran_init_pkt() and tran_destroy_pkt() vectors in the scsi_hba_tran structure must be initialized during the HBA driver's attach(9E) to point to HBA entry points to be called when a target driver calls scsi_init_pkt(9F) and scsi_destroy_pkt(9F). tran_init_pkt() tran_init_pkt() is the entry point into the HBA which is used to allocate and initialize a scsi_pkt structure on behalf of a SCSI target driver. If pkt is NULL, the HBA driver must use scsi_hba_pkt_alloc(9F) to allocate a new scsi_pkt structure. If bp is non-NULL, the HBA driver must allocate appropriate DMA resources for the pkt, for example, throughddi_dma_buf_setup(9F) or ddi_dma_buf_bind_handle(9F). If the PKT_CONSISTENT bit is set in flags, the buffer was allocated by scsi_alloc_consistent_buf(9F). For packets marked with PKT_CONSIS- TENT, the HBA driver must synchronize any cached data transfers before calling the target driver's command completion callback. If the PKT_DMA_PARTIAL bit is set in flags, the HBA driver should set up partial data transfers, such as setting the DDI_DMA_PARTIAL bit in the flags argument if interfaces such as ddi_dma_buf_setup(9F) or ddi_dma_buf_bind_handle(9F) are used. If only partial DMA resources are available, tran_init_pkt() must return in the pkt_resid field of pkt the number of bytes of DMA resources not allocated. If both pkt and bp are non-NULL, if the PKT_DMA_PARTIAL bit is set in flags, and if DMA resources have already been allocated for the pkt with a previous call to tran_init_pkt() that returned a non-zero pkt_resid field, this request is to move the DMA resources for the subsequent piece of the transfer. The contents of scsi_address(9S) pointed to by ap are copied into the pkt_address field of the scsi_pkt(9S) by scsi_hba_pkt_alloc(9F). tgtlen is the length of the packet private area in the scsi_pkt structure to be allocated on behalf of the SCSI target driver. statuslen is the required length for the SCSI status completion block. If the requested status length is greater than or equal to sizeof(struct scsi_arq_status) and the auto_rqsense capability has been set, automatic request sense (ARS) is enabled for this packet. If the status length is less than sizeof(struct scsi_arq_status), automatic request sense must be disabled for this pkt. If the HBA driver is not capable of disabling ARQ on a per-packet basis and tran_init_pkt() is called with a statuslen that is less than sizeof(struct scsi_arq_status), the driver's tran_init_pkt routine should allocate at least sizeof(struct scsi_arq_status). If an ARS is needed, upon successful ARS done by the HBA driver, the driver must copy the sense data over and set STAT_ARQ_DONE in pkt_state. cmdlen is the required length for the SCSI command descriptor block. Note: tgtlen, statuslen, and cmdlen are used only when the HBA driver allocates the scsi_pkt(9S), in other words, when pkt is NULL. callback indicates what the allocator routines should do when resources are not available: NULL_FUNC Do not wait for resources. Return a NULL pointer. SLEEP_FUNC Wait indefinitely for resources. tran_destroy_pkt() tran_destroy_pkt() is the entry point into the HBA that must free all of the resources that were allocated to the scsi_pkt(9S) structure during tran_init_pkt(). RETURN VALUES
tran_init_pkt() must return a pointer to a scsi_pkt(9S) structure on success, or NULL on failure. If pkt is NULL on entry, and tran_init_pkt() allocated a packet throughscsi_hba_pkt_alloc(9F) but was unable to allocate DMA resources, tran_init_pkt() must free the packet through scsi_hba_pkt_free(9F) before returning NULL. SEE ALSO
attach(9E), tran_sync_pkt(9E), biodone(9F), bioerror(9F), ddi_dma_buf_bind_handle(9F), ddi_dma_buf_setup(9F), scsi_alloc_consis- tent_buf(9F), scsi_destroy_pkt(9F), scsi_hba_attach(9F), scsi_hba_pkt_alloc(9F), scsi_hba_pkt_free(9F), scsi_init_pkt(9F), buf(9S), scsi_address(9S), scsi_hba_tran(9S), scsi_pkt(9S) Writing Device Drivers NOTES
If a DMA allocation request fails with DDI_DMA_NOMAPPING, indicate the error by calling bioerror(9F) with bp and an error code of EFAULT. If a DMA allocation request fails with DDI_DMA_TOOBIG, indicate the error by calling bioerror(9F) with bp and an error code of EINVAL. SunOS 5.10 21 Feb 2003 tran_init_pkt(9E)
All times are GMT -4. The time now is 07:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy