Sponsored Content
Top Forums Shell Programming and Scripting Saving file content in arrays using AWK Post 302495009 by atikan on Wednesday 9th of February 2011 05:39:16 AM
Old 02-09-2011
Requirement: To make a script that could extract a few numbers falling in a closed range from a dump file that has the complete list of numbers.
There should be two inputs to this script.
1. the dump file (complete list)
2. the file containing closed ranges (the one that i've mentioned in my previous post) [inp.txt]

Now the script should read from inp.txt and construct an array for the 1st field(start number of range) and another one for the 2nd field(last number of range) and search for this range of numbers from the dump.txt file(complete list of numbers). And save the numbers qualifying in the closed ranges into an output file.

I've made a code that will do the above mentioned searching. But the problem is that i need to feed in the start and end numbers of each range one by one. i want to modify my code upto the next level where it only asks for the file that contains the range lists and keeps running my code until all the records of the range file(inp.txt) have been processed

below is my code
Code:
echo Please input start of range
read min
echo Please input end of range
read max
echo Please input dump file
read file

nawk -v min=$min -v max=$max '$0 >= min && $0 <= max' "$file" >> out.txt

pls tell if there is anything more that u need. thanx
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Content extract of a file using awk

Hi Everyone, I have a file with the below content: File1.txt ====== ### ###==> the below table was created for testing1 purpose; ### create table 123 ( field1 date, field2 char(10) primary key(field1) ); ### ###==> the below table was created... (5 Replies)
Discussion started by: nr_shan
5 Replies

2. Shell Programming and Scripting

saving values in file in an array in awk

hi i am trying to save values in a file in an array in awk..the file is as follows: 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, so far i have this: awk 'BEGIN {RS="\n";FS=","} { for(i=1;i<=NR;i++) { for(j=1;j<=NF;j++) { a=$j; } } (4 Replies)
Discussion started by: npatwardhan
4 Replies

3. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

4. Shell Programming and Scripting

Read a file content with awk and sed

Hello , I have huge file with below content. I need to read the numeric values with in the paranthesis after = sign. Please help me with awk and sed script for it. 11.10.2009 04:02:47 Customer login not found: identifier=(0748502889) prefix=(TEL) serviceCode=(). 11.10.2009 04:03:12... (13 Replies)
Discussion started by: rmv
13 Replies

5. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

6. Shell Programming and Scripting

[ask]awk in csh to extract content from file

Please suggest a method (in c shell or any other shell) to implement following: -To read file1.txt (sample file1 given below) -To save name field in a variable <name> -To save parameter field in a variable <parameter> for ex. let a line in file1.txt be : bill height weight the extracted... (12 Replies)
Discussion started by: animesharma
12 Replies

7. Shell Programming and Scripting

awk saving field of first file into array

Hello guys, I just start trying out AWK and encounter a problem, I try to think a bit but seems my way is incorrect. I have two input file, with the first file has only one field, the second file has 3 fields, I suppose to do stuffs to them by writing an awk program, kinda sort them out. Since I... (15 Replies)
Discussion started by: RozenKristal
15 Replies

8. Shell Programming and Scripting

Change a file content format using awk

Hi, i have a file input.txt Continent North America Country USA Capital Washington D.C. Country Canada Capital Ottawa Continent South America Country Argentina Capital Buenos Aires Country Brazil Capital Brasília Coutry Colombia Capital Bogotá and i want to get an output.txt ... (3 Replies)
Discussion started by: fastlane3000
3 Replies

9. Shell Programming and Scripting

awk : split file and rename and save in path according to content

Hello, I'm using Windows 7 ; sed, awk and gnuwin32 are installed. I have a big text file I need to manipulate. In short, I will have to split it in thousands of short files, then rename and save in a folder which name is based upon filename. Here is a snippet of my big input.txt file (this... (4 Replies)
Discussion started by: sellig
4 Replies

10. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies
NINPATHS(8)						    InterNetNews Documentation						       NINPATHS(8)

NAME
ninpaths - Report Usenet Path statistics (new inpaths) SYNOPSIS
ninpaths -p -d dumpfile ninpaths -r site -u dumpfile [-u dumpfile ...] -v level DESCRIPTION
This is an efficient and space-saving inpaths reporting program. It works as follows: you feed it the Path lines via an INN channel feed or some other similar method, and from time to time the program writes all its internal counters accumulated so far to a dump file. Another instance of the program picks up all the dump files, adds them up and formats them into the report. The purpose of the final report is to summarize the frequency of occurrence of sites in the Path headers of articles. Some central sites accumulate the Path data from many news servers running this program or one like it, and then report statistics on the most frequently seen news servers in Usenet article Path lines. The sendinpaths shell script can be run once a month to mail the accumulated statistics to such a site and remove the old dump files. You can get a working setup by doing the following: 1. Create a directory at pathlog/path (replacing pathlog here and in all steps that follow with the full path to your INN log directory). 2. Set up a channel feed using an entry like: inpaths!:*:Tc,WP:ninpaths -p -d <pathlog>/path/inpaths.%d if your version of INN supports WP (2.0 and later all do). Replace <pathlog> with the full path to your INN log directory. 3. Enter into your news user crontab something like: 6 6 * * * ctlinnd flush inpaths! (the actual time doesn't matter). This will force ninpaths to generate a dump file once a day. 4. Once per month, run the sendinpaths script, which collects the dumps, makes a report, and then deletes the old dumps. (You can generate a report without mailing it and without deleting it with "sendinpaths -n".) OPTIONS
-d dumpfile Save dumps in dumpfile. Any %d in dumpfile will be replaced with the current system time when the dump is made. This option should be used with -p. -p Read Path lines from standard input. -r site Generate a report for site. Generally site should be the value of pathhost from inn.conf. -u dumpfile Read data from dumpfile. This option can be repeated to read data from multiple dump files. -v level Set the verbosity level of the report. Valid values for level are 0, 1, and 2, with 2 being the default. NOTES
If your INN doesn't have the WP feed flag (1.5 does not, 1.6 does, 1.7 I don't know, 2.0 and later all do), use the following newsfeeds entry: inpaths!:*:Tc,WH:ginpaths where ginpaths is the following script: #!/bin/sh exec egrep '^Path: ' | ninpaths -p -d <pathlog>/path/inpaths.%d replacing <pathlog> as above. SEE ALSO
newsfeeds(5), sendinpaths(8) This is a slightly modified version of Olaf Titz's original ninpaths program, which is posted to alt.sources and kept on his WWW archive under <http://sites.inka.de/~bigred/sw/>. HISTORY
ninpaths was written by Olaf Titz <olaf@bigred.inka.de>. The idea and some implementation details for ninpaths come from the original inpaths program, but most of the code has been rewritten for clarity. This program is in the public domain. $Id: ninpaths.pod 7851 2008-05-26 19:33:08Z iulius $ INN 2.5.2 2009-05-21 NINPATHS(8)
All times are GMT -4. The time now is 08:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy