Sponsored Content
Top Forums UNIX for Beginners Questions & Answers (g)awk: Matching strings from one file in another file between two strings Post 303028030 by RudiC on Sunday 30th of December 2018 03:50:14 AM
Old 12-30-2018
You are right, it's clearly written in your spec. He who can read... try


Code:
                else      {if (PR1 && PR2)   {print BUF
                                              print
                                             }
                           STARONE = PR1 = PR2 = 0
                          }
                next 
               }
               {BUF = BUF ORS $0
                if ($1,$2) in T) PR1 = 1
                if ($22 == 503)  PR2 = 1
               }

These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK- delimiting the strings and matching the fields

Hello, I am newbie in awk. I have just started learning it. 1) I have input file which looks like: {4812 4009 1602 2756 306} {4814 4010 1603 2757 309} {8116 9362 10779 } {10779 10121 9193 10963 10908} {1602 2756 306 957 1025} {1603 2757 307} and so on..... 2) In output: a)... (10 Replies)
Discussion started by: kajolo
10 Replies

2. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

3. UNIX for Dummies Questions & Answers

Extraction of strings from a file, after pattern matching

I need to extract strings from a file. The file contains data like: Plan ABCD IN-+-172BB---118C2C---GGN_342-+-MM77_23--+-LAS24_3|GGK_774 | | \-LAS24_2|GGN_774 | +-AA_800_1-+-BAS_000|GGK_362 | | \-BAS_001|GGK_360 | \-DD_000T1---DAM_001|STEEL_0 Plan SHELL_1... (3 Replies)
Discussion started by: abkush
3 Replies

4. Shell Programming and Scripting

Extract two strings from a file and create a new file with these strings

I have the following lines in a log file. It would be great if some one can help me to create a new file with the just entries in the below format. 66.150.161.195 HPSAC=Z05 66.150.161.196 HPSAC=A05 That is just extract the IP address and the string DPSAC=its value 66.150.161.195 -... (1 Reply)
Discussion started by: Tuxidow
1 Replies

5. Shell Programming and Scripting

Need to append matching strings in a file

Hi , I am writing a shell script to check pvsizes in linux box. # for i in `cat vgs1` > do > echo "########### $i ###########" > pvs|grep -i $i|awk '{print $2,$1,$5}'>pvs_$i > pvs|grep -i $i|awk '{print $1}'|while read a > do > fdisk -l $a|head -2|tail -1|awk '{print $2,$3}'>pvs_$i1 >... (3 Replies)
Discussion started by: nanduri
3 Replies

6. Shell Programming and Scripting

awk extract strings matching multiple patterns

Hi, I wasn't quite sure how to title this one! Here goes: I have some already partially parsed log files, which I now need to extract info from. Because of the way they are originally and the fact they have been partially processed already, I can't make any assumptions on the number of... (8 Replies)
Discussion started by: chrissycc
8 Replies

7. UNIX for Dummies Questions & Answers

1st time awk user strings not matching right....

So I was given a file,and I want to count how many occurrences happen with a specific string. I have two, that could have up to 3 different outcomes. Now my trouble I believe starts with this string, "news.cais.net" but why? as of now my output is this... accepted rejected ... (3 Replies)
Discussion started by: squidGreen
3 Replies

8. Shell Programming and Scripting

Output counts of all matching strings lessthan a number using awk

The awk below is supposed to count all the matching $5 strings and count how many $7 values is less than 20. I don't think I need the portion in bold as I do not need any decimal point or format, but can not seem to get the correct counts. Thank you :). file chr5 77316500 77316628 ... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

10. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies
IO::Scalar(3)						User Contributed Perl Documentation					     IO::Scalar(3)

NAME
IO::Scalar - IO:: interface for reading/writing a scalar SYNOPSIS
Perform I/O on strings, using the basic OO interface... use 5.005; use IO::Scalar; $data = "My message: "; ### Open a handle on a string, and append to it: $SH = new IO::Scalar $data; $SH->print("Hello"); $SH->print(", world! Bye now! "); print "The string is now: ", $data, " "; ### Open a handle on a string, read it line-by-line, then close it: $SH = new IO::Scalar $data; while (defined($_ = $SH->getline)) { print "Got line: $_"; } $SH->close; ### Open a handle on a string, and slurp in all the lines: $SH = new IO::Scalar $data; print "All lines: ", $SH->getlines; ### Get the current position (either of two ways): $pos = $SH->getpos; $offset = $SH->tell; ### Set the current position (either of two ways): $SH->setpos($pos); $SH->seek($offset, 0); ### Open an anonymous temporary scalar: $SH = new IO::Scalar; $SH->print("Hi there!"); print "I printed: ", ${$SH->sref}, " "; ### get at value Don't like OO for your I/O? No problem. Thanks to the magic of an invisible tie(), the following now works out of the box, just as it does with IO::Handle: use 5.005; use IO::Scalar; $data = "My message: "; ### Open a handle on a string, and append to it: $SH = new IO::Scalar $data; print $SH "Hello"; print $SH ", world! Bye now! "; print "The string is now: ", $data, " "; ### Open a handle on a string, read it line-by-line, then close it: $SH = new IO::Scalar $data; while (<$SH>) { print "Got line: $_"; } close $SH; ### Open a handle on a string, and slurp in all the lines: $SH = new IO::Scalar $data; print "All lines: ", <$SH>; ### Get the current position (WARNING: requires 5.6): $offset = tell $SH; ### Set the current position (WARNING: requires 5.6): seek $SH, $offset, 0; ### Open an anonymous temporary scalar: $SH = new IO::Scalar; print $SH "Hi there!"; print "I printed: ", ${$SH->sref}, " "; ### get at value And for you folks with 1.x code out there: the old tie() style still works, though this is unnecessary and deprecated: use IO::Scalar; ### Writing to a scalar... my $s; tie *OUT, 'IO::Scalar', $s; print OUT "line 1 line 2 ", "line 3 "; print "String is now: $s " ### Reading and writing an anonymous scalar... tie *OUT, 'IO::Scalar'; print OUT "line 1 line 2 ", "line 3 "; tied(OUT)->seek(0,0); while (<OUT>) { print "Got line: ", $_; } Stringification works, too! my $SH = new IO::Scalar $data; print $SH "Hello, "; print $SH "world!"; print "I printed: $SH "; DESCRIPTION
This class is part of the IO::Stringy distribution; see IO::Stringy for change log and general information. The IO::Scalar class implements objects which behave just like IO::Handle (or FileHandle) objects, except that you may use them to write to (or read from) scalars. These handles are automatically tiehandle'd (though please see "WARNINGS" for information relevant to your Perl version). Basically, this: my $s; $SH = new IO::Scalar $s; $SH->print("Hel", "lo, "); ### OO style $SH->print("world! "); ### ditto Or this: my $s; $SH = tie *OUT, 'IO::Scalar', $s; print OUT "Hel", "lo, "; ### non-OO style print OUT "world! "; ### ditto Causes $s to be set to: "Hello, world! " PUBLIC INTERFACE
Construction new [ARGS...] Class method. Return a new, unattached scalar handle. If any arguments are given, they're sent to open(). open [SCALARREF] Instance method. Open the scalar handle on a new scalar, pointed to by SCALARREF. If no SCALARREF is given, a "private" scalar is created to hold the file data. Returns the self object on success, undefined on error. opened Instance method. Is the scalar handle opened on something? close Instance method. Disassociate the scalar handle from its underlying scalar. Done automatically on destroy. Input and output flush Instance method. No-op, provided for OO compatibility. getc Instance method. Return the next character, or undef if none remain. getline Instance method. Return the next line, or undef on end of string. Can safely be called in an array context. Currently, lines are delimited by " ". getlines Instance method. Get all remaining lines. It will croak() if accidentally called in a scalar context. print ARGS... Instance method. Print ARGS to the underlying scalar. Warning: this continues to always cause a seek to the end of the string, but if you perform seek()s and tell()s, it is still safer to explicitly seek-to-end before subsequent print()s. read BUF, NBYTES, [OFFSET] Instance method. Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error. write BUF, NBYTES, [OFFSET] Instance method. Write some bytes to the scalar. sysread BUF, LEN, [OFFSET] Instance method. Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error. syswrite BUF, NBYTES, [OFFSET] Instance method. Write some bytes to the scalar. Seeking/telling and other attributes autoflush Instance method. No-op, provided for OO compatibility. binmode Instance method. No-op, provided for OO compatibility. clearerr Instance method. Clear the error and EOF flags. A no-op. eof Instance method. Are we at end of file? seek OFFSET, WHENCE Instance method. Seek to a given position in the stream. sysseek OFFSET, WHENCE Instance method. Identical to "seek OFFSET, WHENCE", q.v. tell Instance method. Return the current position in the stream, as a numeric offset. setpos POS Instance method. Set the current position, using the opaque value returned by "getpos()". getpos Instance method. Return the current position in the string, as an opaque object. sref Instance method. Return a reference to the underlying scalar. WARNINGS
Perl's TIEHANDLE spec was incomplete prior to 5.005_57; it was missing support for "seek()", "tell()", and "eof()". Attempting to use these functions with an IO::Scalar will not work prior to 5.005_57. IO::Scalar will not have the relevant methods invoked; and even worse, this kind of bug can lie dormant for a while. If you turn warnings on (via $^W or "perl -w"), and you see something like this... attempt to seek on unopened filehandle ...then you are probably trying to use one of these functions on an IO::Scalar with an old Perl. The remedy is to simply use the OO version; e.g.: $SH->seek(0,0); ### GOOD: will work on any 5.005 seek($SH,0,0); ### WARNING: will only work on 5.005_57 and beyond VERSION
$Id: Scalar.pm,v 1.6 2005/02/10 21:21:53 dfs Exp $ AUTHORS
Primary Maintainer David F. Skoll (dfs@roaringpenguin.com). Principal author Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com). Other contributors The full set of contributors always includes the folks mentioned in "CHANGE LOG" in IO::Stringy. But just the same, special thanks to the following individuals for their invaluable contributions (if I've forgotten or misspelled your name, please email me!): Andy Glew, for contributing "getc()". Brandon Browning, for suggesting "opened()". David Richter, for finding and fixing the bug in "PRINTF()". Eric L. Brine, for his offset-using read() and write() implementations. Richard Jones, for his patches to massively improve the performance of "getline()" and add "sysread" and "syswrite". B. K. Oxley (binkley), for stringification and inheritance improvements, and sundry good ideas. Doug Wilson, for the IO::Handle inheritance and automatic tie-ing. SEE ALSO
IO::String, which is quite similar but which was designed more-recently and with an IO::Handle-like interface in mind, so you could mix OO- and native-filehandle usage without using tied(). Note: as of version 2.x, these classes all work like their IO::Handle counterparts, so we have comparable functionality to IO::String. perl v5.18.2 2005-02-10 IO::Scalar(3)
All times are GMT -4. The time now is 05:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy