Sponsored Content
Top Forums Shell Programming and Scripting Find a string using grep & print the line above or below that. Post 302469235 by Zaib on Friday 5th of November 2010 05:38:23 AM
Old 11-05-2010
I am on Solaris.
& I want this:
Files contains:
Code:
abc
123
def
456
def

Now, I grep def & I want all lines which are immediate above def.
Similar is that with immediate below. I have done this once with just one command but unfortunately I have forgotten.
Please check & share any command.

Last edited by Don Cragun; 09-20-2015 at 06:26 PM.. Reason: Add CODE and ICODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep string and find line before

hi, i have to grep for string in file but i want to find the group of this line so i must get lines before and select the group. the file look like : ####name_groupe1 alphanumeric line alphanumeric line .. ####name_groupe2 alphanumeric line alphanumeric line .. ####name_groupe3... (4 Replies)
Discussion started by: kamel.seg
4 Replies

2. Shell Programming and Scripting

Grep a string and print a string from the line below it

I know how to grep, copy and paste a string from a line. Now, what i want to do is to find a string and print a string from the line below it. To demonstrate: Name 1: ABC Age: 3 Sex: Male Name 2: DEF Age: 4 Sex: Male Output: 3 Male I know how to get "3". My biggest problem is to... (4 Replies)
Discussion started by: kingpeejay
4 Replies

3. Shell Programming and Scripting

Perl : Find a string and Print full line

Hi Need a perl script to read lines in a file, scan for a string named "APPLE" and write to different file the only lines containing the matched string. (5 Replies)
Discussion started by: PrasannaKS
5 Replies

4. Shell Programming and Scripting

awk find a string, print the line 2 lines below it

I am parsing a nagios config, searching for a string, and then printing the line 2 lines later (the "members" string). Here's the data: define hostgroup{ hostgroup_name chat-dev alias chat-dev members thisisahostname } define hostgroup{ ... (1 Reply)
Discussion started by: mglenney
1 Replies

5. Shell Programming and Scripting

grep a string and print strings on that line

i have a file like below ABS 12234 A C 12G CFY 23865 A C 34D i want to grep "A C" then print ABS 12G 12234 CFY 34D 23865 Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

6. Shell Programming and Scripting

find string nth occurrence in file and print line number

Hi I have requirement to find nth occurrence in a file and capture data from with in lines (between lines) Data in File. <QUOTE> <SESSION> <ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/> <ATTRIBUTE NAME='Service Name' VALUE='None'/> </SESSION> <SESSION> <ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies

7. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

8. Shell Programming and Scripting

Need to print the next word from the same line based on grep string condtion match.

I need to fetch particular string from log file based on grep condition match. Actual requirement is need to print the next word from the same line based on grep string condtion match. File :Java.lanag.xyz......File copied completed : abc.txt Ouput :abc.txt I have used below... (5 Replies)
Discussion started by: siva83
5 Replies

9. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

10. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies
one-bit-instrument(7)						  Numm Tutorials					     one-bit-instrument(7)

NAME
one bit instrument - how to make a gnarly synth with numm-run SYNOPSIS
numm-run FILE DESCRIPTION
In this tutorial we will learn how to live-code a one-bit synthesizer controlled by mouse position. It is intended as a gentle introduc- tion to development with numm-run. To get started, create a text file with the following method stubs: def audio_out(a): pass def video_out(a): pass Save the file as onebit.py, and then launch it with numm-run: numm-run onebit.py You should see a blank window appear. We will now make some sound and light by changing the value of a in the audio_out and video_out functions: def audio_out(a): a[::100] = 2**15 def video_out(a): a.flat[::100] = 255 Save the file, and you should see and hear the sketch update. This is using numpy's array-indexing to turn every hundredth audio sample and pixel-color on. The audio sample rate is by default 44100Hz, so it produces a series of clicks that will be perceived as a 441Hz tone. We can turn this into an instrument by connecting mouse motion to frequency: period = 100 def audio_out(a): a[::period] = 2**15 def video_out(a): a.flat[::period] = 255 def mouse_in(type,px,py,button): global period period = px*1000 Finally, let's use the keyboard to record and jump to notes. The first time you press a key, it records the period, and subsequant depres- sions play the saved period: period = 100 record = {} def audio_out(a): a[::period] = 2**15 def video_out(a): a.flat[::period] = 255 def mouse_in(type,px,py,button): global period period = px*1000 def keyboard_in(type,key): global period if record.has_key(key): period = record[key] elif record.has_key(key): record[] = period SEE ALSO
numm-run(1), numm.getting-started(7), numm.spectral-analysis(7) numm February 2012 one-bit-instrument(7)
All times are GMT -4. The time now is 04:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy