Sponsored Content
Top Forums Shell Programming and Scripting Extract data based on position Post 302473011 by ctsgnb on Thursday 18th of November 2010 05:14:06 PM
Old 11-18-2010
@Chubler :

If the matching is similar, then consider the following example
(we can then proceed by analogy adapting the matching to our needs)

Code:
[ctsgnb@shell ~]$ cat mys
toto
bla
124
125
[ctsgnb@shell ~]$ cat myfile
134512345 toto whateva
124523043 hhhh nothing
123512344 anyword bla
125412450 hshs juju
124452344 titi bla
123451345 hhhhhhh tatat
[ctsgnb@shell ~]$ sed 's/.*/^&/' mys
^toto
^bla
^124
^125
[ctsgnb@shell ~]$ sed 's/.*/^&/' mys | grep -f - myfile
124523043 hhhh nothing
125412450 hshs juju
124452344 titi bla
[ctsgnb@shell ~]$

another one :

Code:
[ctsgnb@shell ~]$ cat myfile
134512345 toto whateva
124523043 hhhh nothing
124599943 bla nothing
123512344 anyword bla
125412450 hshs juju
124452344 titi bla
123451345 hhhhhhh toto
125412450 bla juju
125412450 toto juju
[ctsgnb@shell ~]$ cat mys
toto
bla
124
125
[ctsgnb@shell ~]$ sed 's/.*/^.\\{10\\}&/' mys | grep -f - myfile
134512345 toto whateva
124599943 bla nothing
125412450 bla juju
125412450 toto juju
[ctsgnb@shell ~]$

so
Code:
sed 's/.*/^&/' patternfile | grep -f - mydatafile


Last edited by ctsgnb; 11-18-2010 at 06:27 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

2. UNIX for Dummies Questions & Answers

To Extract words from File based on Position

Hi Guys, While I was writing one shell script , I just got struck at this point. I need to extract words from a file at some specified position and do some comparison operation and need to replace the extracted word with another word. Eg : I like Orange very much. I need to replace... (19 Replies)
Discussion started by: kuttu123
19 Replies

3. UNIX for Dummies Questions & Answers

Extract Data and arrange it based on timelines

Hi Im trying to extract a specific pattern of data from a log file and store it in a other file, Im executing the below command in various files and storing it in a single file. I data that Im storing needs to be arranged based on a date and timestamp. Please assist, how to achieve this. Thanks... (1 Reply)
Discussion started by: vr3w3c9
1 Replies

4. Shell Programming and Scripting

How to extract log data based on date

Hi Gurus, I've been having some problem in extracting the log data based on the current date and month. As shown in the sample data below, how to extract the log info for Aug 11? Sample data: root pts/ta userpc Wed Aug 11 09:46 - 20:21 (10:35) root pts/ta userpc... (13 Replies)
Discussion started by: superHonda123
13 Replies

5. Shell Programming and Scripting

Extract data based on specific search criteria

I have a huge file (about 2 millions records) contains data separated by “,” (comma). As part of the requirement, I can't change the format. The objective is to remove some of the records with the following condition. If the 23rd field on each line start with 302 , I need to remove that from the... (4 Replies)
Discussion started by: jaygamini
4 Replies

6. Shell Programming and Scripting

Cut multiple data based on character position

How to extract multiple data based on character position. I need to fetch from 7-9 and 22-26 and there is no delimiter for 22-26 since it is part of the column. The file may have more than 1000 character long.I managed to pull any one but not both for example test data 12345 zxc vbnmlk... (1 Reply)
Discussion started by: zooby
1 Replies

7. Shell Programming and Scripting

Help with grouping data based on range position

Input file: data_1 1000 1290 data_4 290 234 data_2 1114 1110 data_5 534 999 data_6 900 1050 . . Desired_output_file_1_0_999: data_4 290 234 data_5 534 999 Desired_output_file_2_1000_1999: data_1 1000 1290 data_2 1114 1110 (1 Reply)
Discussion started by: perl_beginner
1 Replies

8. Shell Programming and Scripting

extract data in a csv file based on a certain field.

I have a csv file that I need to extract some data from depending on another field after reading info from another text file. The text file would say have 592560 in it. The csv file may have some data like so Field 1 Field2 Field3 Field4 Field5 Field6 20009756 1 ... (9 Replies)
Discussion started by: GroveTuckey
9 Replies

9. UNIX for Dummies Questions & Answers

extract regions of file based on start and end position

Hi, I have a file1 of many long sequences, each preceded by a unique header line. file2 is 3-columns list: headers name, start position, end position. I'd like to extract the sequence region of file1 specified in file2. Based on a post elsewhere, I found the code: awk... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

10. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies
XML::Mini::Element::DocType(3pm)			User Contributed Perl Documentation			  XML::Mini::Element::DocType(3pm)

NAME
XML::Mini::Element::DocType - represents DocType header in XML::Mini parser DESCRIPTION
The XML::Mini::Element::DocType is used internally to represent <!DOCTYPE bla bla [ ... ]>. You shouldn't need to use it directly, see XML::Mini::Element's docType() method. AUTHOR
Copyright (C) 2002-2008 Patrick Deegan, Psychogenic Inc. Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file). If you wish to include these modules in non-GPL code, you need prior written authorisation from the authors. This library is released under the terms of the GNU GPL version 3, making it available only for free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details). Anyone wishing to use this library within a proprietary or otherwise non- GPLed program MUST contact psychogenic.com to acquire a distinct license for their application. This approach encourages the use of free software while allowing for proprietary solutions that support further development. LICENSE XML::Mini::Element module, part of the XML::Mini XML parser/generator package. Copyright (C) 2002-2008 Patrick Deegan All rights reserved XML::Mini is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. XML::Mini 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 the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XML::Mini. If not, see <http://www.gnu.org/licenses/>. Official XML::Mini site: http://minixml.psychogenic.com Contact page for author available on http://www.psychogenic.com/ SEE ALSO
XML::Mini, XML::Mini::Document, XML::Mini::Element http://minixml.psychogenic.com perl v5.10.0 2009-09-20 XML::Mini::Element::DocType(3pm)
All times are GMT -4. The time now is 05:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy