Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Search a string and display its location on the entire string and make a text file Post 302995030 by ANKIT ROY on Friday 31st of March 2017 05:02:56 AM
Old 03-31-2017
Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-31-2017 at 06:11 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies

2. Shell Programming and Scripting

Search a string and append text after the string

Hi, I have a file like this... <o t="Batch" id="8410" p="/" g="32"> <a n="name"> <v s="DBBA1MM"/> </a> <a n="owner"> <v r="/Administrator"/> </a> <a n="rights"> <v s="95"/> </a> <a n="debugLevel"> <v s="3"/> </a> <a n="avsStoreLoc"> <v... (8 Replies)
Discussion started by: kesu2k
8 Replies

3. UNIX for Dummies Questions & Answers

Search for a string and copy the entire line

Hello All, I am after the script or the command which can scan the entire file for a string $PART_ID and when found to extract/copy the corresponding $PART_ID value (e.g THIRE_PTY_SOFTWARE for the 1st occurance of $PART_ID in the attached file) to a file. Appreciate your help. Thanks in... (3 Replies)
Discussion started by: forumthreads
3 Replies

4. Shell Programming and Scripting

search for a string in a text file

I want to write a script to check for duplicates For example: I have a text file with information in the format of /etc/passwd alice:x:1008:555:William Williams:/home/bill:/bin/bash bob:x:1018:588:Bobs Boos:/home/bob:/bin/bash bob:x:1019:528:Robt Ross:/home/bob:/bin/bash james:x:1012:518:Tilly... (3 Replies)
Discussion started by: ixDLxi
3 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

7. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

8. Programming

Search a string in a text file in C

Hello guys, i want some help please in coding that program , " A mini dictionary" the file looks like : Waver --- To be hesitated retirement --- life after end of career The user enter the word , and then it prints the meaning of it Please use CODE tags when... (4 Replies)
Discussion started by: Alyy
4 Replies

9. Shell Programming and Scripting

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

10. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies
Weather::Com::Cached(3pm)				User Contributed Perl Documentation				 Weather::Com::Cached(3pm)

NAME
Weather::Com::Cached - Perl extension for getting weather information from weather.com SYNOPSIS
use Data::Dumper; use Weather::Com::Cached; # define parameters for weather search my %params = ( 'cache' => '/tmp/weathercache', 'current' => 1, 'forecast' => 3, 'links' => 1, 'units' => 's', 'proxy' => 'http://proxy.sonstwo.de', 'timeout' => 250, 'debug' => 1, 'partner_id' => 'somepartnerid', 'license' => '12345678', ); # instantiate a new weather.com object my $cached_weather = Weather::Com::Cached->new(%params); # search for locations called 'Heidelberg' my $locations = $cached_weather->search('Heidelberg') or die "No location found! "; # and then get the weather for each location found foreach (keys %{$locations}) { my $weather = $cached_weather->get_weather($_); print Dumper($weather); } DESCRIPTION
Weather::Com::Cached is a Perl module that provides low level OO interface to gather all weather information that is provided by weather.com. Please refer to Weather::Com for the high level interfaces. This module implements the caching business rules that apply to all applications programmed against the xoap API of weather.com. Except from the cache parameter to be used while instantiating a new object instance, this module has the same API than Weather::Com::Base. It's only a simple caching wrapper around it. The caching mechanism for location searches is very simple. We assume that location codes on weather.com will never change. Therefore, a search string that has been successfully used once to search for locations will never cause another search on the web. Each location search results will be stored in the file "locations.dat". If you want to refresh your locations cache, simply delete this file. Although it's really simple, the module uses Storable methods lock_store and lock_retrieve to implement shared locking for reading cache files and exclusive locking for writing to chache files. By this way the same cache files should be able to be used by several application instances using Weather::Com::Cached. You'll need to register at weather.com to to get a free partner id and a license key to be used within all applications that you want to write against weather.com's xoap interface. <http://www.weather.com/services/xmloap.html> CHANGES
The location caching mechanism has been extended with version 0.4. Up to V0.4 searches were stored this way: $locations_cache = { 'New York' => { 'USNY1000' => 'New York/La Guardia Arpt, NY', 'USNY0998' => 'New York/Central Park, NY', 'USNY0999' => 'New York/JFK Intl Arpt, NY', 'USNY0996' => 'New York, NY' }, } This has changed the way it does not only store a search_string => locations hash. The cache now also stores a hash for each location name found: $locations_cache => { 'new york' => { 'USNY1000' => 'New York/La Guardia Arpt, NY', 'USNY0998' => 'New York/Central Park, NY', 'USNY0999' => 'New York/JFK Intl Arpt, NY', 'USNY0996' => 'New York, NY' }, 'new york/central park, ny' => { 'USNY0998' => 'New York/Central Park, NY' }, 'new york/la guardia arpt, ny' => { 'USNY1000' => 'New York/La Guardia Arpt, NY' }, 'new york, ny' => { 'USNY0996' => 'New York, NY' }, 'new york/jfk intl arpt, ny' => { 'USNY0999' => 'New York/JFK Intl Arpt, NY' }, } The new mechanism has the following advantages: 1. The new chaching mechanism is case insensitive 2. This caching mechanism is a workaround one problem with weather.com's XOAP API. Their server does not understand any search string with a '/' in it - no matter wether the '/' is URL encoded or not! This way, if you have searched for New York once, you'll then also get a result for direct calls to New York/Jfk Intl Arpt, NY. 3. The new mechanism also allows searches for slashed substrings. A search for York/Central will return the New York/Central Park, NY location and if you simply search York, you'll get anything containing York. No matter if it's in the cache or not. Only if you specify exactly the name of a location in the cache, only this location is shown. CONSTRUCTOR
new(hash or hashref) This constructor takes the same hash or hashref as Weather::Com::Base does. Please refer to that documentation for further details. Except from the Weather::Com::Base's parameters this constructor takes a parameter cache which defines the path to a directory into which all cache files will be put. The cache directory defaults to '.'. METHODS
search(search string) The "search()" method has the same interface as the one of Weather::Com::Base. The difference is made by the caching. The search is performed in the following order: 1. If there's a direct match in the locations cache, return the locations from the cache. 2. If not, if there's a direct match on the web, return the locations found on the web and write the search result to the cache. 3. If not, try a regexp search over all cached search strings and location names. This will return each location that matches the search string. The rest is all the same as for Weather::Com::Base. SEE ALSO
See also documentation of Weather::Com and Weather::Com::Base. AUTHOR
Thomas Schnuecker, <thomas@schnuecker.de> COPYRIGHT AND LICENSE
Copyright (C) 2004-2007 by Thomas Schnuecker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The data provided by weather.com and made accessible by this OO interface can be used for free under special terms. Please have a look at the application programming guide of weather.com! <http://www.weather.com/services/xmloap.html> perl v5.8.8 2007-07-09 Weather::Com::Cached(3pm)
All times are GMT -4. The time now is 05:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy