Sponsored Content
Top Forums Shell Programming and Scripting Displaying text till pattern match found in a line Post 302764253 by jim mcnamara on Thursday 31st of January 2013 07:39:14 AM
Old 01-31-2013
Code:
awk -F '.'   '/[Pp]assed/{print $1 ;getline;print $1}' file_name

If you display several line of text from you input file, maybe we can do better than just guess as to what we we're reading. I do not see why you have getline in there. Your expected output is just a single line, per your example.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

2. Shell Programming and Scripting

Print characters till the next space when the pattern is found

i have a file which contains alphanumeric data in every line. what i need is the data after certain pattern. the data after the pattern is not of fixed length so i need the data till the space after the pattern. Input file: bfdkasfbdfg khffkf lkdhfhdf pattern (datarequired data not required)... (2 Replies)
Discussion started by: gpk_newbie
2 Replies

3. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

4. Shell Programming and Scripting

Pattern match till the end of the file.

I have a file which is like this ……………………………………….. ………………………………… ………………………………… …………………………………… ……………………………………. ……………………………… <<<from_here>>> ……………………………… ………………………………. I want a script which would fetch the data starting from <<<from_here>>> in the file till the end... (2 Replies)
Discussion started by: halfafringe
2 Replies

5. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

6. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

7. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

8. Shell Programming and Scripting

Append text on particular line after pattern found

hi, i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6". original l6:6:wait:/etc/rc.d/rc 6 after-change l6:6:wait:/etc/rc.d/rc 6 /sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
IO::Handle::Prototype::Fallback(3pm)			User Contributed Perl Documentation		      IO::Handle::Prototype::Fallback(3pm)

NAME
IO::Handle::Prototype::Fallback - Create IO::Handle like objects using a set of callbacks. SYNOPSIS
my $fh = IO::Handle::Prototype::Fallback->new( getline => sub { my $fh = shift; ... }, ); DESCRIPTION
This class provides a way to define a filehandle based on callbacks. Fallback implementations are provided to the extent possible based on the provided callbacks, for both writing and reading. SPECIAL CALLBACKS
This class provides two additional methods on top of IO::Handle, designed to let you implement things with a minimal amount of baggage. The fallback methods are all best implemented using these, though these can be implemented in terms of Perl's standard methods too. However, to provide the most consistent semantics, it's better to do this: IO::Handle::Prototype::Fallback->new( __read => sub { shift @array; }, ); Than this: IO::Handle::Prototype::Fallback->new( getline => sub { shift @array; }, ); Because the fallback implementation of "getline" implements all of the extra crap you'd need to handle to have a fully featured implementation. __read Return a chunk of data of any size (could use $/ or not, it depends on you, unlike "getline" which probably should respect the value of $/). This avoids the annoying "substr" stuff you need to do with "read". __write $string Write out a string. This is like a simplified "print", which can disregard $, and "$" as well as multiple argument forms, and does not have the extra "substr" annoyance of "write" or "syswrite". WRAPPING
If you provide a single reading related callback ("__read", "getline" or "read") then your callback will be used to implement all of the other reading primitives using a string buffer. These implementations handle $/ in all forms ("undef", ref to number and string), all the funny calling conventions for "read", etc. FALLBACKS
Any callback that can be defined purely in terms of other callbacks in a way will be added. For instance "getc" can be implemented in terms of "read", "say" can be implemented in terms of "print", "print" can be implemented in terms of "write", "write" can be implemented in terms of "print", etc. None of these require special wrapping and will always be added if their dependencies are present. GLOB OVERLOADING
When overloaded as a glob a tied handle will be returned. This allows you to use the handle in Perl's IO builtins. For instance: my $line = <$fh> will not call the "getline" method natively, but the tied interface arranges for that to happen. perl v5.10.1 2009-09-29 IO::Handle::Prototype::Fallback(3pm)
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy