Sponsored Content
Top Forums Shell Programming and Scripting Modifying text file records, find data in one place in the record and print it elsewhere Post 302987922 by RudiC on Sunday 18th of December 2016 08:57:27 AM
Old 12-18-2016
Let me applaud you to your efforts to circumnavigate the problems you encountered and to your (can I say: ) endurance in finding a solution on your own, as opposed to coming back whining immediately. Other members could certainly take a leaf out of your book!


Trying to answer some of your questions:
- I'd be surprised if extra lines were added if the loop starts with i=1, at least it didn't when I tested it. And, why should it?
- /var/ in awk is a regex constant, so it would try to match the sequence of chars'v', 'a', and 'r'. Your last approach is the right one to match variables.
- awk works on pattern {action} pairs. action is executed if pattern is TRUE. So, F is equivalent to F != 0 as awk treats 0 as FALSE and anything else as TRUE.
- shell scripts are interpreted line by line, even in a loop, and files for e.g. output are opened and closed for every redirection encountered (e.g. echo or printf command). awk reads a script, compiles, and executes it. Files are kept open unless explicitly closed. This will make up for the main execution time difference. Although you are not using external commands (which would consume resources for a process creation for each and make it even slower), some of your statements could be improved.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find Duplicate Records in a text file

Hi all pls help me by providing soln for my problem I'm having a text file which contains duplicate records . Example: abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 tas 3420 3562 ... (1 Reply)
Discussion started by: G.Aavudai
1 Replies

2. Shell Programming and Scripting

converting all records of a file in to one record

I have a file temp.dat. The contents of this file is as follows abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh The multiple records in this file needs to be converted in to a single record. abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh (2 Replies)
Discussion started by: rsriramiyer
2 Replies

3. Shell Programming and Scripting

Find lines in text file with certain data in first field

Hi all, Sorry for the title, I was unsure how to word my issue. I'll get right to the issue. In my text file, I need to find all lines with the same data in the first field. Then I need to create a file with the matching lines merged into one. So my original file will look something like... (4 Replies)
Discussion started by: rstev39147
4 Replies

4. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies

5. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

6. Shell Programming and Scripting

Searching for a particular string and modifying text within block of data

Hi Forum. Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for. I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the... (5 Replies)
Discussion started by: pchang
5 Replies

7. Shell Programming and Scripting

Find x and print its record

Hi all, I have a file containing two fields with 154 rows/records/lines (forgive me, my UNIX terminology is not quite up to par yet). I am trying to read from this list, find a value (lets say 0), then print the record/line/row that value falls on (In this case it would be record/line/row #27)?... (5 Replies)
Discussion started by: StudentServitor
5 Replies

8. Shell Programming and Scripting

Find and remove duplicate record and print list

Gents, I needs to delete duplicate values and only get uniq values based in columns 2-27 Always we should keep the last record found... I need to store one clean file and other with the duplicate values removed. Input : S3033.0 7305.01 0 420123.8... (18 Replies)
Discussion started by: jiam912
18 Replies

9. Shell Programming and Scripting

awk print matching records and occurences of each record

Hi all , I have two files : dblp.xml with dblp records and itu1.txt with faculty members records. I need to find out how many dblp records are related to the faculty members. More specific: I need to find out which names from itu1.txt are a match in dblp. xml file , print them and show how many... (4 Replies)
Discussion started by: iori
4 Replies

10. Shell Programming and Scripting

Find key pattern and print selected lines for each record

Hi, I need help on a complicated file that I am working on. I wanted to extract important info from a very huge file. It is space delimited file. I have hundred thousands of records in this file. An example content of the inputfile as below:- ## ID Ser402 Old; 23... (2 Replies)
Discussion started by: redse171
2 Replies
wcmgr(1)							   The Webalizer							  wcmgr(1)

NAME
wcmgr - Webalizer (DNS) Cache file Manager SYNOPSIS
wcmgr [ option ... ] cache-file DESCRIPTION
wcmgr is a utility program which allows manipulation of the DNS cache files used and produced by The Webalizer. Each record in the cache file contains an IP address (either IPv4 or IPv6), a timestamp of when the entry was added to the cache, a flag to indicate if the record contains a resolved name or not, and either the same IP address or a resolved host name. All records are accessed by their IP address. RUNNING WCMGR
wcmgr was designed to be run from the Unix shell command line. This facilitates its use in shell scripts and other automated processes. A valid DNS cache file must be specified. Command line options are optional, and if none are given, the default action is to list the con- tents of the specified cache file. COMMAND LINE OPTIONS
Different functions are selected by using one or more of the following command line options. If no options are given, the default is to display the contents of the cache file to the screen (stdout). -h Display all available command line options and exit. -v Be verbose. -V Display the program version and exit. Additional program specific information will be displayed if verbose mode is also used (e.g. '-vV'), which can be useful when submitting bug reports. -a address [-n hostname] [-t0] Add a new record to the cache file. The IP address will be added to the cache file using the current time as the timestamp and with a resolved name hostname. If -t0 is specified, the record will be considered permanent, and will not be removed (during a purge) or expired. If a hostname is not specified with the -n option, then the address will be used instead, and the record will be flagged as unresolved. -c Create a new cache file. If used alone, this option will create a new, empty cache file. If used with the import option, a new cache file will be created before importing the data. An error will occur if the file cache-file already exists. -d address Delete a record from the cache file using the specified address. -f address Find and display information for address from the cache file. A single line similar to that produced by the -l option will be dis- played unless verbose mode is enabled, in which case a more detailed listing will be produced. -i name [-c] Import data into the cache file from the file name. The import file must be a valid tab delimited text file, such as that created by the export option. If the imported data contains records already present in the cache file, those records will be overwritten by the imported data. The cache file must exist unless the -c option is specified, in which case, a new cache file will be created for the imported data. -l List the contents of the cache file. This is the default action of the program, so does not necessarily need to be specified. If verbose mode is enabled, a report title, column headers and summary totals will also be displayed. -p num Purge the cache file of entries older than num days. If num is not specified, then a default of 7 days will be used. if verbose mode is enabled, each purged record will be printed and the total number of purged records will be displayed. -s [-t num] Display cache file information/statistics. If a TTL value (in days) is specified using the -t option, it will be used to calculate how many records are older than num days, otherwise, the default value of 7 days will be used. -n name Specify the name to use as the resolved hostname when adding records to the cache. -t num Time to live (TTL) value. If used along with the -p (purge) option, it specifies how many days a record will remain valid. Any record that is older than num days is considered expired and will be purged. If used with the -a (add) option, a zero value will cause the record to be considered permanent. -x name Export data from a cache file to a tab delimited text file named name. If the text file name exists, it will be overwritten. BUGS
Please report bugs to the author. COPYRIGHT
Copyright (C) 1997-2011 by Bradford L. Barrett. Distributed under the GNU GPL. See the files "COPYING" and "Copyright", supplied with all distributions for additional information. AUTHOR
Bradford L. Barrett <brad at mrunix dot net> Version 1.00 12-Jul-2008 wcmgr(1)
All times are GMT -4. The time now is 07:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy