Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell - Read a text file with two words and extract data Post 302983648 by Scrutinizer on Friday 14th of October 2016 09:37:41 AM
Old 10-14-2016
Hi RudiC, yes, except for leading spaces and extra new lines, and:
Code:
awk '{$1=$1}1' RS=, newtest2.txt > output.txt

would be a full solution.

But I assumed the OP wanted a shell solution, since that is what the OP was using and I assumed he was going to do some further processing within the loop.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to read all the unique words in a text file

How can i read all the unique words in a file, i used - cat comment_file.txt | /usr/xpg6/bin/tr -sc 'A-Za-z' '/012' and cat comment_file.txt | /usr/xpg6/bin/tr -sdc 'A-Za-z' '/012' but they didnt worked..... (5 Replies)
Discussion started by: aditya.ece1985
5 Replies

2. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies

3. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

4. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

5. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies

6. Shell Programming and Scripting

Script to read file and extract data by matching pattern

Hello, I have a file ( say file1) which has lines like below. xxxx:xxxx,yyyy,1234,efgh zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo dddd:dddd here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by "," In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies

7. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

8. Shell Programming and Scripting

I need to extract uique words from text file

Hello programmers, I need to create a list of unique words from a text file using PERL...may i have the code for that please? Thank you (1 Reply)
Discussion started by: alsohari
1 Replies

9. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

10. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies
Text::Context::EitherSide(3pm)				User Contributed Perl Documentation			    Text::Context::EitherSide(3pm)

NAME
Text::Context::EitherSide - Get n words either side of search keywords SYNOPSIS
use Text::Context::EitherSide; my $text = "The quick brown fox jumped over the lazy dog"; my $context = Text::Context::EitherSide->new($text); $context->as_string("fox") # "... quick brown fox jumped over ..." $context->as_string("fox", "jumped") # "... quick brown fox jumped over the ..." my $context = Text::Context::EitherSide->new($text, context => 1); # 1 word on either side $context->as_string("fox", "jumped", "dog"); # "... brown fox jumped over ... lazy dog", Or, if you don't believe in all this OO rubbish: use Text::Context::EitherSide qw(get_context); get_context(1, $text, "fox", "jumped", "dog") # "... brown fox jumped over ... lazy dog" DESCRIPTION
Suppose you have a large piece of text - typically, say, a web page or a mail message. And now suppose you've done some kind of full-text search on that text for a bunch of keywords, and you want to display the context in which you found the keywords inside the body of the text. A simple-minded way to do that would be just to get the two words either side of each keyword. But hey, don't be too simple minded, because you've got to make sure that the list doesn't overlap. If you have the quick brown fox jumped over the lazy dog and you extract two words either side of "fox", "jumped" and "dog", you really don't want to end up with quick brown fox jumped over brown fox jumped over the the lazy dog so you need a small amount of smarts. This module has a small amount of smarts. EXPORTABLE
get_context This is primarily an object-oriented module. If you don't care about that, just import the "get_context" subroutine, and call it like so: get_context($num_of_words, $text, @words_to_find) and you'll get back a string with ellipses as in the synopsis. That's all that most people need to know. But if you want to do clever stuff... METHODS
new my $c = Text::Context::EitherSite->new($text [, context=> $n]); Create a new object storing some text to be searched, plus optionally some information about how many words on either side you want. (If you don't like the default of 2.) context $c->context(5); Allows you to get and set the number of the words on either side. as_sparse_list $c->as_sparse_list(@keywords) Returns the keywords, plus n words on either side, as a sparse list; the original text is split into an array of words, and non-contextual elements are replaced with "undef"s. (That's not actually how it works, but conceptually, it's the same.) as_list $c->as_list(@keywords) The same as "as_sparse_list", but single or multiple "undef"s are collapsed into a single ellipsis: (undef, "foo", undef, undef, undef, "bar") becomes ("...", "foo", "...", "bar") as_string $c->as_string(@keywords) Takes the "as_list" output above and joins them all together into a string. This is what most people want from "Text::Context::EitherSide". EXPORT "get_context" is available as a shortcut for Text::Context::EitherSide->new($text, context => $n)->as_string(@words); but needs to be explicitly imported. Nothing is exported by default. SEE ALSO
Text::Context is an even smarter way of extracting a contextual string. AUTHOR
Current maintainer: Tony Bowden Original author: Simon Cozens BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Text-Context-EitherSide@rt.cpan.org COPYRIGHT AND LICENSE
Copyright 2002-2005 by Kasei Limited, http://www.kasei.com/ You may use and redistribute this module under the terms of the Artistic License 2.0. http://www.perlfoundation.org/artistic_license_2_0 perl v5.10.0 2009-05-04 Text::Context::EitherSide(3pm)
All times are GMT -4. The time now is 05:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy