Search text and delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search text and delete
# 1  
Old 03-29-2006
Search text and delete

After searching for a specified string, I would like to delete couple of rows from the file and continue searching. Basically, I would like to search through a text file that holds logs with date-time stamp in them and then clean up the file if the log entry is more than 2 days old.

Example log entries:

02.01.06 03:08:20.040 Output: 34 Bytes ==> 4472
???"?????????__ABCL__??__ABCL__À?

02.05.06 03:08:20.040 Output: 34 Bytes ==> 4472
???"?????????__CEDL__??__CEDL__À?

In the above example, I would like to delete the two lines for the entry from 02.01.06 and keep 02.05.06 if today is 02.05.06

Thanks.

Last edited by new2shell; 03-29-2006 at 11:08 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a text and return the text from file

Hi I have a set of input strings in a pattern as given below string1 string2 string3 string4 string5 I need to search this sequence of strings from a file in such a way that the first two strings (string1 and string2) and last two strings (string4 and string5) should match with the... (8 Replies)
Discussion started by: my_Perl
8 Replies

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

3. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

4. Shell Programming and Scripting

Search and delete

A file(example viv.txt) contains a n number of rows like 1,2,3,4,5,6,7,8 11,22,33,44,55,66,77,88 1,3,9,7,8,5,2,6,4 Requirement: If number "5" exist in the sixth position then it should delete the whole line.like this it should check for all rows in a file(viv.txt) . please help on this. (5 Replies)
Discussion started by: katakamvivek
5 Replies

5. Shell Programming and Scripting

Search and delete

Gurus I have a CSV containing 60K records.Each row has 8 columns. On some rows ,for the 7th column ,i find word 'UnknownState(898914497)' repeated many times. e.g <N_HOST> <tcp> <*> <*> <*> <*> ... (1 Reply)
Discussion started by: ak835
1 Replies

6. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

7. Shell Programming and Scripting

Advanced Search & Delete Text File

I have a file in which email messages are stored in. Every email is separated by by a ^Z character (Control-Z). I need to extract all emails after the 65,00th one to another file and delete them from the original file. Any suggests on accomplishing this? (2 Replies)
Discussion started by: maxcell
2 Replies

8. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question
AUSEARCH:(8)						  System Administration Utilities					      AUSEARCH:(8)

NAME
ausearch - a tool to query audit daemon logs SYNOPSIS
ausearch [options] DESCRIPTION
ausearch is a tool that can query the audit daemon logs based for events based on different search criteria. The ausearch utility can also take input from stdin as long as the input is the raw log data. Each commandline option given forms an "and" statement. For example, searching with -m and -ui means return events that have both the requested type and match the user id given. An exception is the -n option; multiple nodes are allowed in a search which will return any matching node. It should also be noted that each syscall excursion from user space into the kernel and back into user space has one event ID that is unique. Any auditable event that is triggered during this trip share this ID so that they may be correlated. Different parts of the kernel may add supplemental records. For example, an audit event on the syscall "open" will also cause the kernel to emit a PATH record with the file name. The ausearch utility will present all records that make up one event together. This could mean that even though you search for a specific kind of record, the resulting events may contain SYSCALL records. Also be aware that not all record types have the requested information. For example, a PATH record does not have a hostname or a loginuid. OPTIONS
-a, --event audit-event-id Search for an event based on the given event ID. Messages always start with something like msg=audit(1116360555.329:2401771). The event ID is the number after the ':'. All audit events that are recorded from one application's syscall have the same audit event ID. A second syscall made by the same application will have a different event ID. This way they are unique. -c, --comm comm-name Search for an event based on the given comm name. The comm name is the executable's name from the task structure. -e, --exit exit-code-or-errno Search for an event based on the given syscall exit code or errno. -f, --file file-name Search for an event based on the given filename. -ga, --gid-all all-group-id Search for an event with either effective group ID or group ID matching the given group ID. -ge, --gid-effective effective-group-id Search for an event with the given effective group ID or group name. -gi, --gid group-id Search for an event with the given group ID or group name. -h, --help Help -hn, --host host-name Search for an event with the given host name. The hostname can be either a hostname, fully qualified domain name, or numeric network address. No attempt is made to resolve numeric addresses to domain names or aliases. -i, --interpret Interpret numeric entities into text. For example, uid is converted to account name. The conversion is done using the current resources of the machine where the search is being run. If you have renamed the accounts, or don't have the same accounts on your machine, you could get misleading results. -if, --input file-name Use the given file instead of the logs. This is to aid analysis where the logs have been moved to another machine or only part of a log was saved. --input-logs Use the log file location from auditd.conf as input for searching. This is needed if you are using ausearch from a cron job. --just-one Stop after emitting the first event that matches the search criteria. -k, --key key-string Search for an event based on the given key string. -l, --line-buffered Flush output on every line. Most useful when stdout is connected to a pipe and the default block buffering strategy is undesirable. May impose a performance penalty. -m, --message message-type | comma-sep-message-type-list Search for an event matching the given message type. You may also enter a comma separated list of message types. There is an ALL message type that doesn't exist in the actual logs. It allows you to get all messages in the system. The list of valid messages types is long. The program will display the list whenever no message type is passed with this parameter. The message type can be either text or numeric. If you enter a list, there can be only commas and no spaces separating the list. -n, --node node-name Search for events originating from node name string. Multiple nodes are allowed, and if any nodes match, the event is matched. -o, --object SE-Linux-context-string Search for event with tcontext (object) matching the string. -p, --pid process-id Search for an event matching the given process ID. -pp, --ppid parent-process-id Search for an event matching the given parent process ID. -r, --raw Output is completely unformatted. This is useful for extracting records that can still be interpretted by audit tools. -sc, --syscall syscall-name-or-value Search for an event matching the given syscall. You may either give the numeric syscall value or the syscall name. If you give the syscall name, it will use the syscall table for the machine that you are using. -se, --context SE-Linux-context-string Search for event with either scontext/subject or tcontext/object matching the string. --session Login-Session-ID Search for events matching the given Login Session ID. This process attribute is set when a user logs in and can tie any process to a particular user login. -su, --subject SE-Linux-context-string Search for event with scontext (subject) matching the string. -sv, --success success-value Search for an event matching the given success value. Legal values are yes and no. -te, --end [end-date] [end-time] Search for events with time stamps equal to or before the given end time. The format of end time depends on your locale. If the date is omitted, today is assumed. If the time is omitted, now is assumed. Use 24 hour clock time rather than AM or PM to specify time. An example date using the en_US.utf8 locale is 09/03/2009. An example of time is 18:00:00. The date format accepted is influenced by the LC_TIME environmental variab le. You may also use the word: now, recent, today, yesterday, this-week, week-ago, this-month, this-year. Today means starting now. Recent is 10 minutes ago. Yesterday is 1 second after midnight the previous day. This-week means starting 1 second after midnight on day 0 of the week determined by your locale (see localtime). This-month means 1 second after midnight on day 1 of the month. This-year means the 1 second after midnight on the first day of the first month. -ts, --start [start-date] [start-time] Search for events with time stamps equal to or after the given end time. The format of end time depends on your locale. If the date is omitted, today is assumed. If the time is omitted, midnight is assumed. Use 24 hour clock time rather than AM or PM to specify time. An example date using the en_US.utf8 locale is 09/03/2009. An example of time is 18:00:00. The date format accepted is influ- enced by the LC_TIME environmental variable. You may also use the word: now, recent, today, yesterday, this-week, this-month, this-year. Today means starting at 1 second after midnight. Recent is 10 minutes ago. Yesterday is 1 second after midnight the previous day. This-week means starting 1 second after midnight on day 0 of the week determined by your locale (see localtime). This-month means 1 second after midnight on day 1 of the month. This-year means the 1 second after midnight on the first day of the first month. -tm, --terminal terminal Search for an event matching the given terminal value. Some daemons such as cron and atd use the daemon name for the terminal. -ua, --uid-all all-user-id Search for an event with either user ID, effective user ID, or login user ID (auid) matching the given user ID. -ue, --uid-effective effective-user-id Search for an event with the given effective user ID. -ui, --uid user-id Search for an event with the given user ID. -ul, --loginuid login-id Search for an event with the given login user ID. All entry point programs that are pamified need to be configured with pam_loginuid required for the session for searching on loginuid (auid) to be accurate. -v, --version Print the version and exit -w, --word String based matches must match the whole word. This category of matches include: filename, hostname, terminal, and SE Linux con- text. -x, --executable executable Search for an event matching the given executable name. SEE ALSO
auditd(8), pam_loginuid(8). Red Hat Sept 2009 AUSEARCH:(8)