Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help please, extract multiple lines from a text file Post 302413016 by Franklin52 on Wednesday 14th of April 2010 08:59:45 AM
Old 04-14-2010
Quote:
Originally Posted by posix
if i want these two in run time input
Code:
#!/bin/sh
file=~/test/imm_del.txt
read -p "provide your first input" read1
read -p "provide your 2nd input" read2
awk -v var1="$read1" -v var2="$read2" "/^var1/{p=1}/^var2/{p=0;print }p" $file

But it not working Smilie
With awk variables it should be like:
Code:
#!/bin/sh

file=~/test/imm_del.txt
read -p "provide your first input" read1
read -p "provide your 2nd input" read2

awk -v var1="$read1" -v var2="$read2" '$1==var1{p=1}$1==var2{p=0;print}p' $file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple repeated data from a text file

Hi, I need to extract data from a text file in which data has a pattern. I need to extract all repeated pattern and then save it to different files. example: input is: ST*867*000352214 BPT*00*1000352214*090311 SE*1*1 ST*867*000352215 BPT*00*1000352214*090311 SE*1*2 ... (5 Replies)
Discussion started by: apjneeraj
5 Replies

2. Shell Programming and Scripting

extract the lines between specific line number from a text file

Hi I want to extract certain text between two line numbers like 23234234324 and 54446655567567 How do I do this with a simple sed or awk command? Thank you. ---------- Post updated at 06:16 PM ---------- Previous update was at 05:55 PM ---------- found it: sed -n '#1,#2p'... (1 Reply)
Discussion started by: return_user
1 Replies

3. Shell Programming and Scripting

extract particular lines from text file

I have two files file A which have a number in every row and file B which contains few hundred thousand rows with about 300 characters in each row (csv) What I need is to extract whole rows from B file (only these which numbers are indicated in A file) I also need to use cygwin. Any... (7 Replies)
Discussion started by: gunio
7 Replies

4. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

5. Shell Programming and Scripting

Extract strings from multiple lines into one file -

input file Desired csv output gc_type, date/time, milli secs af, Mar 17 13:09:04 2011, 144.596 af, Mar 20 00:37:37 2011, 144.242 af, ar 20 21:30:59 2011, 108.518 Hi All, Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies

6. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

7. Shell Programming and Scripting

Extracting Multiple Lines from a Text File

Hello. I am sorry if this is a common question but through all my searching, I haven't found an answer which matches what I want to do. I am looking for a sed command that will parse through a large text file and extract lines that start with specific words (which are repeated throughout the... (4 Replies)
Discussion started by: MrDumbQuestion
4 Replies

8. Shell Programming and Scripting

Process multiple lines in a text file

Hi All I have text file like this: a=21ej c=3tiu32 e=hydkehw f=hgdiuw g=jhdkj a=klkjhvl b=dlkjhyfd a=yo c=8732 Any way I can process data from first a to just before of second a, and then second a to just before of 3rd one. Just fetching records like that will help, I mean... (3 Replies)
Discussion started by: sandipjee
3 Replies

9. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

10. Shell Programming and Scripting

Extract a pattern from multiple lines in a file

I have a file that has some lines starts with * I want to get these lines, then get the word between "diac" and "lex". ex. file: ;;WORD AlAx *0.942490 diac:Al>ax lex:>ax_1 bw:Al/DET+>ax/NOUN+ gloss:brother pos:noun prc3:0 prc2:0 prc1:0 prc0:Al_det per:na asp:na vox:na mod:na gen:m num:s... (4 Replies)
Discussion started by: Viernes
4 Replies
NetAddr::IP::UtilPP(3)					User Contributed Perl Documentation				    NetAddr::IP::UtilPP(3)

NAME
NetAddr::IP::UtilPP -- pure Perl functions for NetAddr::IP::Util SYNOPSIS
use NetAddr::IP::UtilPP qw( hasbits shiftleft addconst add128 sub128 notcontiguous ipv4to6 mask4to6 ipanyto6 maskanyto6 ipv6to4 bin2bcd bcd2bin ); use NetAddr::IP::UtilPP qw(:all) $rv = hasbits($bits128); $bitsX2 = shiftleft($bits128,$n); $carry = addconst($ipv6naddr,$signed_32con); ($carry,$ipv6naddr)=addconst($ipv6naddr,$signed_32con); $carry = add128($ipv6naddr1,$ipv6naddr2); ($carry,$ipv6naddr)=add128($ipv6naddr1,$ipv6naddr2); $carry = sub128($ipv6naddr1,$ipv6naddr2); ($spurious,$cidr) = notcontiguous($mask128); ($carry,$ipv6naddr)=sub128($ipv6naddr1,$ipv6naddr2); $ipv6naddr = ipv4to6($netaddr); $ipv6naddr = mask4to6($netaddr); $ipv6naddr = ipanyto6($netaddr); $ipv6naddr = maskanyto6($netaddr); $netaddr = ipv6to4($pv6naddr); $bcdtext = bin2bcd($bits128); $bits128 = bcd2bin($bcdtxt); DESCRIPTION
NetAddr::IP::UtilPP provides pure Perl functions for NetAddr::IP::Util o $rv = hasbits($bits128); This function returns true if there are one's present in the 128 bit string and false if all the bits are zero. i.e. if (hasbits($bits128)) { &do_something; } or if (hasbits($bits128 & $mask128) { &do_something; } This allows the implementation of logical functions of the form of: if ($bits128 & $mask128) { ... input: 128 bit IPv6 string returns: true if any bits are present o $bitsXn = shiftleft($bits128,$n); input: 128 bit string variable, number of shifts [optional] returns: bits X n shifts NOTE: input bits are returned if $n is not specified o addconst($ipv6naddr,$signed_32con); Add a signed constant to a 128 bit string variable. input: 128 bit IPv6 string, signed 32 bit integer returns: scalar carry array (carry, result) o add128($ipv6naddr1,$ipv6naddr2); Add two 128 bit string variables. input: 128 bit string var1, 128 bit string var2 returns: scalar carry array (carry, result) o sub128($ipv6naddr1,$ipv6naddr2); Subtract two 128 bit string variables. input: 128 bit string var1, 128 bit string var2 returns: scalar carry array (carry, result) Note: The carry from this operation is the result of adding the one's complement of ARG2 +1 to the ARG1. It is logically NOT borrow. i.e. if ARG1 >= ARG2 then carry = 1 or if ARG1 < ARG2 then carry = 0 o ($spurious,$cidr) = notcontiguous($mask128); This function counts the bit positions remaining in the mask when the rightmost '0's are removed. input: 128 bit netmask returns true if there are spurious zero bits remaining in the mask, false if the mask is contiguous one's, 128 bit cidr o $ipv6naddr = ipv4to6($netaddr); Convert an ipv4 network address into an ipv6 network address. input: 32 bit network address returns: 128 bit network address o $ipv6naddr = mask4to6($netaddr); Convert an ipv4 netowrk address into an ipv6 network mask. input: 32 bit network/mask address returns: 128 bit network/mask address NOTE: returns the high 96 bits as one's o $ipv6naddr = ipanyto6($netaddr); Similar to ipv4to6 except that this function takes either an IPv4 or IPv6 input and always returns a 128 bit IPv6 network address. input: 32 or 128 bit network address returns: 128 bit network address o $ipv6naddr = maskanyto6($netaddr); Similar to mask4to6 except that this function takes either an IPv4 or IPv6 netmask and always returns a 128 bit IPv6 netmask. input: 32 or 128 bit network mask returns: 128 bit network mask o $netaddr = ipv6to4($pv6naddr); Truncate the upper 96 bits of a 128 bit address and return the lower 32 bits. Returns an IPv4 address as returned by inet_aton. input: 128 bit network address returns: 32 bit inet_aton network address o $bcdtext = bin2bcd($bits128); Convert a 128 bit binary string into binary coded decimal text digits. input: 128 bit string variable returns: string of bcd text digits o $bits128 = bcd2bin($bcdtxt); Convert a bcd text string to 128 bit string variable input: string of bcd text digits returns: 128 bit string variable EXPORT_OK hasbits shiftleft addconst add128 sub128 notcontiguous ipv4to6 mask4to6 ipanyto6 maskanyto6 ipv6to4 bin2bcd bcd2bin comp128 bin2bcdn bcdn2txt bcdn2bin simple_pack threads AUTHOR
Michael Robinton <michael@bizsystems.com> COPYRIGHT
Copyright 2003 - 2012, Michael Robinton <michael@bizsystems.com> All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or b) the "Artistic License" which comes with this distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details. You should have received a copy of the Artistic License with this distribution, in the file named "Artistic". If not, I'll be glad to provide one. You should also have received a copy of the GNU General Public License along with this program in the file named "Copying". If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA or visit their web page on the internet at: http://www.gnu.org/copyleft/gpl.html. AUTHOR
Michael Robinton <michael@bizsystems.com> perl v5.18.2 2012-08-10 NetAddr::IP::UtilPP(3)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy