Sponsored Content
Top Forums Shell Programming and Scripting How to grab data between 2 strings ? Post 302091622 by ghostdog74 on Wednesday 4th of October 2006 04:05:06 AM
Old 10-04-2006
Alternative in Python:

Input:
blah
xxx
yyy
**********************************************************
** 05T00NPQSMR1 P98P2234 Tue 10 03 09:57:24 2006
** dibid= 1166 testerid= 6
** sample= 100 0
** tasM= MFMM xx xx xx
** tasC= MFMC xx xx xx
************************************
xxxx
yyy
zzz
blah
blah
**********************************************************
** 05T00NPQSMR1 P98P2234 Tue 10 03 09:57:24 2006
** dibid= 1166 testerid= 6
** sample= 100 0
** tasM= MFMM xx xx xx
** tasC= MFMC xx xx xx
************************************
xxxasdfljsdlfx
yyy;slkfd;s
zzzsdklfjsd
blasdflksdjh
blajaspofkspodf



Code:
number = []
all = open("test.txt").readlines()
for num,line in enumerate(all):
 	line = line.strip()
 	if "*" * 58 in line:
 		number.append(num)
 

for i in range(len(number)):
 	try:
 		print ''.join(all[ number[i]:number[i+1] ] )
 	except:
 		print ''.join(all[number[i]:])


Output:
**********************************************************
** 05T00NPQSMR1 P98P2234 Tue 10 03 09:57:24 2006
** dibid= 1166 testerid= 6
** sample= 100 0
** tasM= MFMM xx xx xx
** tasC= MFMC xx xx xx
************************************
xxxx
yyy
zzz
blah
blah

**********************************************************
** 05T00NPQSMR1 P98P2234 Tue 10 03 09:57:24 2006
** dibid= 1166 testerid= 6
** sample= 100 0
** tasM= MFMM xx xx xx
** tasC= MFMC xx xx xx
************************************
xxxasdfljsdlfx
yyy;slkfd;s
zzzsdklfjsd
blasdflksdjh
blajaspofkspodf

Last edited by ghostdog74; 10-05-2006 at 04:34 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

search and grab data from a huge file

folks, In my working directory, there a multiple large files which only contain one line in the file. The line is too long to use "grep", so any help? For example, if I want to find if these files contain a string like "93849", what command I should use? Also, there is oder_id number... (1 Reply)
Discussion started by: ting123
1 Replies

2. UNIX for Dummies Questions & Answers

grab the data from the unix window

Hi, How could i grab a set of data (eg:file execution start & stop time stamp f) from unix? (1 Reply)
Discussion started by: siriv
1 Replies

3. Shell Programming and Scripting

Using Python to grab data from a website

Hello Everyone, I'm trying to write a python script that will go to the following website and grab all the data on the page. The page refreshes regularly and the number of flights is different. Untitled Document What I wanted to do was grab all the data (except for top three row containing... (5 Replies)
Discussion started by: jl487
5 Replies

4. Shell Programming and Scripting

Grab the data

Hello Honourable Members, I stuck into one issue, my server is migrating from UNIX to linux and ptree command does not work there. I was working with pstree command in linux and need some help regarding the same. suppose i have one line for example: ram (121)--- sita... (3 Replies)
Discussion started by: singhabm
3 Replies

5. Shell Programming and Scripting

How to grab data from xml block?

I tried searching the forums, but couldn't find anything relevant to my question. I have an xml file like the following: <topLevel numberBlock="BLOCK1"> <item="content1" title="Content 1"> <RefPath="path/to/file1.txt /> </item> <item"content2" title="Content 2" >... (4 Replies)
Discussion started by: jl487
4 Replies

6. Shell Programming and Scripting

Grab data between 2 keywords any do an array operation and write the file intact

Hi Unix Gurus, I need to grep for a block that is between a start and end keyword and then in between I need to find and replace a keyword. for eg: I need to search between Test = 000; and Test = 000; and find K9 and replace with M9 INPUT FILE Define { Replace = K9; Test =... (6 Replies)
Discussion started by: naveen@
6 Replies

7. Shell Programming and Scripting

Grab 2 pieces of data within a file

I am a newbie and what I have is a captured file of content. I want to be able to grab 2 pieces of data, multiple times and print them to the screen. DataFile owner: locke user: fun data size: 60 location: Anaheim owner: david user: work data size: 80 location: Orange my script... (2 Replies)
Discussion started by: greglocke
2 Replies

8. Shell Programming and Scripting

Grab data within a table in a long log file.

in my file which is a rather long log file it contains many text and tables and there is one table with 15 columns and I am interested to read in the value in column6 and its corresponding value in column2. Trouble is I do not know how to script it as the line number various between different log... (8 Replies)
Discussion started by: piynik
8 Replies

9. Shell Programming and Scripting

How to grab a block of data in a file with repeating pattern?

I need to send email to receipient in each block of data in a file which has the sender address under TO and just send that block of data where it ends as COMPANY. I tried to work this out by getting line numbers of the string HELLO but unable to grab the next block of data to send the next... (5 Replies)
Discussion started by: loggedout
5 Replies

10. Shell Programming and Scripting

awk to grab data in range then search for pattern

im using the following code to grab data, but after the data in the range im specifying has been grabbed, i want to count how many instances of a particular pattern is found? awk 'BEGIN{count=0} /parmlib.*RSP/,/seqfiles.*SSD/ {print; count++ } /103 error in ata file/ END { print count }'... (3 Replies)
Discussion started by: SkySmart
3 Replies
syncloop(1M)						  System Administration Commands					      syncloop(1M)

NAME
syncloop - synchronous serial loopback test program SYNOPSIS
/usr/sbin/syncloop [-cdlstv] device DESCRIPTION
The syncloop command performs several loopback tests that are useful in exercising the various components of a serial communications link. Before running a test, syncloop opens the designated port and configures it according to command line options and the specified test type. It announces the names of the devices being used to control the hardware channel, the channel number (ppa) corresponding to the device argument, and the parameters it has set for that channel. It then runs the loopback test in three phases. The first phase is to listen on the port for any activity. If no activity is seen for at least four seconds, syncloop proceeds to the next phase. Otherwise, the user is informed that the line is active and that the test cannot proceed, and the program exits. In the second phase, called the "first-packet" phase, syncloop attempts to send and receive one packet. The program will wait for up to four seconds for the returned packet. If no packets are seen after five attempts, the test fails with an excoriating message. If a packet is returned, the result is compared with the original. If the length and content do not match exactly, the test fails. The final phase, known as the "multiple-packet" phase, attempts to send many packets through the loop. Because the program has verified the integrity of the link in the first-packet phase, the test will not fail after a particular number of timeouts. If a packet is not seen after four seconds, a message is displayed. Otherwise, a count of the number of packets received is updated on the display once per second. If it becomes obvious that the test is not receiving packets during this phase, the user may wish to stop the program manually. The number and size of the packets sent during this phase is determined by default values, or by command line options. Each returned packet is com- pared with its original for length and content. If a mismatch is detected, the test fails. The test completes when the required number of packets have been sent, regardless of errors. After the multiple-packet phase has completed, the program displays a summary of the hardware event statistics for the channel that was tested. The display takes the following form: CRC errors Aborts Overruns Underruns In<-Drops-> Out 0 0 0 0 0 0 This is followed by an estimated line speed, which is an approximation of the bit rate of the line, based on the number of bytes sent and the actual time that it took to send them. OPTIONS
The options for syncloop are described in the following table: Option Parameter Default Description -c packet_count 100 Specifies the number of pack- ets to be sent in the multi- ple-packet phase. -d hex_data_byte random Specifies that each packet will be filled with bytes with the value of hex_data_byte. -l packet_length 100 Specifies the length of each packet in bytes. -s line_speed 9600 Bit rate in bits per second. -v Sets verbose mode. If data errors occur, the expected and received data is dis- played. -t test_type none A number, from 1 to 4, that specifies which test to per- form. The values for test_type are as follows: 1: Internal loopback test. Port loopback is on. Transmit and receive clock sources are internal (baud rate genera- tor). 2: External loopback test. Port loopback is off. Transmit and receive clock sources are internal. Requires a loopback plug suitable to the port under test. 3: External loopback test. Port loopback is off. Transmit and receive clock sources are external (modem). Requires that one of the local modem, the remote modem, or the remote system be set in a loopback configu- ration. 4: Test using prede- fined parameters. User defines hardware configura- tion and may select port parameters using the syncinit(1M) command. All numeric options except -d are entered as decimal numbers (for example, -s 19200). If you do not provide the -t test_type option, syn- cloop prompts for it. EXAMPLES
Example 1: A sample display of using the syncloop command. In the following command syncloop uses a packet length of 512 bytes over the first CPU port: example# syncloop -l 512 zsh0 In response to the above command, syncloop prompts you for the test option you want. The following command performs an internal loopback test on the first CPU port, using 5000 packets and a bit rate of 56Kbps: example# syncloop -t 1 -s 56000 -c 5000 zsh0 ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
syncinit(1M), syncstat(1M), attributes(5), zsh(7D) DIAGNOSTICS
device missing minor device number The name device does not end in a decimal number that can be used as a minor device number. invalid packet length: nnn The packet length was specified to be less than zero or greater than 4096. poll: nothing to read poll: nothing to read or write. The poll(2) system call indicates that there is no input pending and/or that output would be blocked if attempted. len xxx should be yyy The packet that was sent had a length of yyy, but was received with a length of xxx. nnn packets lost in outbound queueing nnn packets lost in inbound queueing A discrepancy has been found between the number of packets sent by syncloop and the number of packets the driver counted as transmit- ted, or between the number counted as received and the number read by the program. WARNINGS
To allow its tests to run properly, as well as prevent disturbance of normal operations, syncloop should only be run on a port that is not being used for any other purpose at that time. SunOS 5.10 9 Mar 1993 syncloop(1M)
All times are GMT -4. The time now is 05:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy