Sponsored Content
Top Forums Shell Programming and Scripting Script to count matched string then check again from last read position Post 302990162 by rbatte1 on Monday 23rd of January 2017 07:31:47 AM
Old 01-23-2017
An alternate may be to open the file with tail and keep it open.

What is your overall aim for this process? You might be able to:-
Code:
while read line
do
   process "$line"
done < <(tail -f $logfile)

I think that the < <(command) is a bash construct rather than sh or ksh so it depends if you have that or even if this is appropriate. This process will not end, but continue reading the log file when new records are written, so it's near-time (strictly not quite real-time)

Beware that the log file will remain open, so if you rotate your log files, you might need to use tail -F $logfile instead to open the replacement file.


Can you tell us what the point of this code is to be? There may be a simpler way that I'm not thinking of. It would be useful to know the OS version (output from uname -a) and shell that you are using.



Kind regards,
Robin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

2. Shell Programming and Scripting

Read string from a file,plz help me to check

#!/usr/bin/ksh exec 0<property while read newReceiveDir do if then sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh elif then sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh ... (1 Reply)
Discussion started by: joshuaduan
1 Replies

3. UNIX for Dummies Questions & Answers

Count of matched pattern occurance

In a file a pattern is occured many times randomly. Even it may appear more then once in the same line too. How i can get the number of times that pattern appeared in the file? let the file name is abc.txt and the pattern is "xyz". I used the following code: grep -ic "xyz" abc.txt but it is... (3 Replies)
Discussion started by: palash2k
3 Replies

4. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Script To read Date and count from files

Smaple 1 Date and Time: 2013-05-11 12:23:12 MST abc,1234,hi-all,45354-88888,IN,US XYZ,1234,hi-all,45354-88888,OUT,GB abc,1234,hi-all,45354-88888,IN,AS abc,1234,hi-all,45354-88888,OUT,US abc,1234,hi-all,45354-88888,IN,US Number of Records: 000005 Sample 2 HDR: 20130511... (1 Reply)
Discussion started by: Abhisrajput
1 Replies

7. Shell Programming and Scripting

Write a word at 72nd position of a matched line in a file

Hi, I need to search a file for a pattern,replace some other word and write a word at its 72nd position. For example, My name is Mano.Im learning Unix. I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And... (5 Replies)
Discussion started by: mano1 n
5 Replies

8. UNIX for Dummies Questions & Answers

I need a Script to read Log string and check date at the same time

I need to check 1 log file, which is logging: 2014-08-18T09:10:39+02:00 user: XXXXX START FEATURE 2014-08-18T09:10:39+02:00 user: XXXXX FINISH FEATURE I first need to check that the START FEATURE starts and finish on the same time/date for the same user, which is different each time START... (2 Replies)
Discussion started by: TheBest43
2 Replies

9. 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

10. UNIX for Beginners Questions & Answers

Count exact matched words

hi , i have a file test.dat which contains following data. test.dat XY|abc@xyz.com XY|abc@xyz.com ST|abc@xyz.com ST|abc@xyz.com ST|XYZ@abc.com FK|abc@xyz.com FK|STG@xyz.com FK|abc@xyz.com FK|FKG@xyz.com i want to know the count of XY,ST,FK. i.e XY = 2 , ST = 3 , FK = 4 I am... (4 Replies)
Discussion started by: itzkashi
4 Replies
MEDIT(1)						      General Commands Manual							  MEDIT(1)

NAME
medit - text editor SYNOPSIS
medit [OPTION]... [FILES] DESCRIPTION
medit is a text editor. OPTIONS
-n, --new-app run new instance of medit. By default medit opens FILES (or creates a new document if none are given) in an existing instance of application -s, --use-session[=yes|no] load and save session. By default medit does it when -n is not used. If this option is not given on command line then medit uses the corresponding preferences setting. --pid PID use existing instance with process id PID. --app-name NAME use instance name NAME. If an instance with this name is already running, then it will send files given on the command line to that instance and exit. -e, --encoding ENCODING use provided character encoding to open the file -l, --line LINE open file and position cursor on line LINE. Alternatively line number may be specified with filename, e.g. medit foo.txt:12 -r, --reload automatically reload opened file if it was modified on disk by another program. -w, --new-window open file in a new window. -t, --new-tab open file in a new tab. --log-file FILE write debug output into FILE. This option is only useful on Windows. --log-window show debug output in a log window. This option is only useful on Windows. --debug DOMAINS enable debug output for DOMAINS (if medit was compiled with --enable-debug option). --geometry WIDTHxHEIGHT --geometry WIDTHxHEIGHT+X+Y default window size and position. -h, --help show summary of options. -v, --version show program version. FILES list of files to open. Filenames may include line numbers after colon, e.g. /tmp/file.txt:200. Trailing colon is ignored. ENVIRONMENT VARIABLES
MEDIT_PID if set, it is used as --pid argument. When medit spawns a process (e.g. a DVI viewer) it sets MEDIT_PID to its own process id, so the child process may in turn simply use 'medit filename' to open a file (e.g. for inverse DVI search). CONTACT
http://mooedit.sourceforge.net/contact.html AUTHOR
Written and maintained by Yevgen Muntyan <emuntyan@users.sourceforge.net> September 2010 MEDIT(1)
All times are GMT -4. The time now is 07:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy