Sponsored Content
Top Forums Shell Programming and Scripting searching and editing file contents Post 302164746 by jayana on Tuesday 5th of February 2008 08:39:25 PM
Old 02-05-2008
searching and editing file contents

Can you please help me to edit parts of a file and write into a new file.
=====================================
Suppose I have a huge data dump in a file I need to search for a tag in that and cut few lines around that tag in the file. Is there a way to keep track of line numbers and operate on the file.

I can explain with example.
I have this file AAA
-----AAA------
Start:
name:1111
date:222
id:3333
address:12444
end
Start:
name:5555
date:3312
id:6666
address:qwds
end
Start:
name:7777
date:9090
id:4571
address:abc444
end
----------------
ID is unique for each start-end block in above file.
In above file, I need to search for a ID, say 4571 and just extract the block Start-End having details about id:4571
expected output is:
name:7777
date:9090
id:4571
address:abc444

can you please suggest how I can go about getting the necessary data from AAA given a ID as input?

Last edited by jayana; 02-05-2008 at 10:05 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Searching contents of a file

Is there a way a command or a combination through which i can check the contents of a all files in a directory and get the return as the file names which contains the partiuclar string. (2 Replies)
Discussion started by: thepitzaboy
2 Replies

2. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

3. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

4. Shell Programming and Scripting

Problem with searching and then editing a file through shell.

Hi, I have searched through this forum as there are many similar entries but could'nt get one of them to work, either that or they were just different to what I needed. Basically I have a file, recordsDatabase. In this file are a few different fields. There is a unique identifier eg 001... (5 Replies)
Discussion started by: U_C_Dispatj
5 Replies

5. Shell Programming and Scripting

Help in searching a particular string in a file name (not inside the file contents)

Dear Unix Gurus, I am new to shell scripting and in the process of learing. I am trying to find whether a file name has today's date in MMDDYYYY format. I am using the following code and it doesn't seem like working. #!/usr/bin/ksh today=$(date '+%m%d%Y') echo today: $today file=`find... (4 Replies)
Discussion started by: shankar1dada
4 Replies

6. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

7. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

8. Shell Programming and Scripting

Problem with the awk in searching the contents in a file

Hello all, I am a newbie in awk. I am struggling in this problem for a long.Actually I have two files, filea and fileb. File a is actually a search key through it I have to find the corresponding japanese tag from file b. filea contains the data like this: sm982882 sm1893548 sm2420025... (3 Replies)
Discussion started by: csim_mohan
3 Replies

9. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

10. Shell Programming and Scripting

Searching the pattern and accordingly changing the contents using shell

HI, I have File1 which contains :- admins = anand,satheesha,user1,user2,user3,user4,user5,user10,vishal nonadmins = read-only @admins = rw @nonadmins = r One shell script, using that I want to change the File1 as per user input (let's say $1) which have value as 'John', so now I want to... (6 Replies)
Discussion started by: Vishal Mishra
6 Replies
NOTMUCH-SEARCH-TERMS(7) 				 Miscellaneous Information Manual				   NOTMUCH-SEARCH-TERMS(7)

NAME
notmuch-search-terms - Syntax for notmuch queries SYNOPSIS
notmuch count [options...] <search-term>... notmuch dump [ <filename> ] [--] [ <search-term>...] notmuch search [options...] <search-term>... notmuch show [options...] <search-term>... notmuch tag +<tag>|-<tag> [...] [--] <search-term>... DESCRIPTION
Several notmuch commands accept a common syntax for search terms. The search terms can consist of free-form text (and quoted phrases) which will match all messages that contain all of the given terms/phrases in the body, the subject, or any of the sender or recipient headers. As a special case, a search string consisting of exactly a single asterisk ("*") will match all messages. In addition to free text, the following prefixes can be used to force terms to match against specific portions of an email, (where <brack- ets> indicate user-supplied values): from:<name-or-address> to:<name-or-address> subject:<word-or-quoted-phrase> attachment:<word> tag:<tag> (or is:<tag>) id:<message-id> thread:<thread-id> folder:<directory-path> The from: prefix is used to match the name or address of the sender of an email message. The to: prefix is used to match the names or addresses of any recipient of an email message, (whether To, Cc, or Bcc). Any term prefixed with subject: will match only text from the subject of an email. Searching for a phrase in the subject is supported by including quotation marks around the phrase, immediately following subject:. The attachment: prefix can be used to search for specific filenames (or extensions) of attachments to email messages. For tag: and is: valid tag values include inbox and unread by default for new messages added by notmuch new as well as any other tag values added manually with notmuch tag. For id:, message ID values are the literal contents of the Message-ID: header of email messages, but without the '<', '>' delimiters. The thread: prefix can be used with the thread ID values that are generated internally by notmuch (and do not appear in email messages). These thread ID values can be seen in the first column of output from notmuch search The folder: prefix can be used to search for email message files that are contained within particular directories within the mail store. Only the directory components below the top-level mail database path are available to be searched. In addition to individual terms, multiple terms can be combined with Boolean operators ( and, or, not , etc.). Each term in the query will be implicitly connected by a logical AND if no explicit operator is provided, (except that terms with a common prefix will be implicitly combined with OR until we get Xapian defect #402 fixed). Parentheses can also be used to control the combination of the Boolean operators, but will have to be protected from interpretation by the shell, (such as by putting quotation marks around any parenthesized expression). Finally, results can be restricted to only messages within a particular time range, (based on the Date: header) with a syntax of: <initial-timestamp>..<final-timestamp> Each timestamp is a number representing the number of seconds since 1970-01-01 00:00:00 UTC. This is not the most convenient means of expressing date ranges, but until notmuch is fixed to accept a more convenient form, one can use the date program to construct timestamps. For example, with the bash shell the following syntax would specify a date range to return messages from 2009-10-01 until the current time: $(date +%s -d 2009-10-01)..$(date +%s) SEE ALSO
notmuch(1), notmuch-config(1), notmuch-count(1), notmuch-dump(1), notmuch-hooks(5), notmuch-new(1), notmuch-reply(1), notmuch-restore(1), notmuch-search(1), notmuch-show(1), notmuch-tag(1) Notmuch 0.13.2 2012-06-01 NOTMUCH-SEARCH-TERMS(7)
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy