Search for a particular string in a paragraph in a text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for a particular string in a paragraph in a text
# 1  
Old 04-07-2010
Search for a particular string in a paragraph in a text

Hi all,

i'm new to this community. I am trying to write a script which will fetch ftp completion time of a file from a paragraph of a big text file ( which contains multiple paragraphs) . Each paragraph will have ftp details..

Now I dont know how to fetch process time within a paragraph of a big text file.

example:

/home/a_mstpap/clientoutbound/trigger/APO_FXEXG_20090406_235735.txt.txt.TRG
220 gti0s052 FTP server (SecureTransport 4.6.1) ready.
331 Password required for wlthmgmt.
230 Virtual user wlthmgmt logged in.
200 PORT command successful.
150 Opening ASCII mode data connection for ste1824a/fxexg/APO_FXEXG_20090406_235735.txt.txt.
226 Transfer complete.
Process Completion time 20090406-23:57:58

/home/a_mstpap/clientoutbound/trigger/WEALTHTOUC_FXEXG_20090406_235736.txt.txt.TRG
archive clientoutbound dead.letter discard email fileArchive logs notify.lst notify.sav scripts_shared
Processing file /home/a_mstpap/clientoutbound/trigger/WEALTHTOUC_FXEXG_20090406_235736.txt.txt...
archive clientoutbound dead.letter discard email fileArchive logs notify.lst notify.sav scripts_shared
The trigger 220 DataExpress FTP Server ready.
331 Password required for ste2930z.
230 User WEALTHTOUCH - STE2930Z logged in to DataExpress.
200 PORT command successful.
150 Opening data connection 221 Goodbye.
Process Completion time 20090406-23:58:32


here I have two paragraphs which has file name and its process completion time each..First I have to search the particular para for a file and then check its process time.how do I do it..pls help..thanks
# 2  
Old 04-07-2010
Here is a quick solution to get the line with the file and completion time.
Code:
 sed -n '/^\//N;s/\n.*$/ /p;/^Process /s/^.* \([0-9]\)/\1/p' file

# 3  
Old 04-07-2010
A Perl solution -

Code:
$ 
$ cat f7
/home/a_mstpap/clientoutbound/trigger/APO_FXEXG_20090406_235735.txt.txt.TRG
220 gti0s052 FTP server (SecureTransport 4.6.1) ready.
331 Password required for wlthmgmt.
230 Virtual user wlthmgmt logged in.
200 PORT command successful.
150 Opening ASCII mode data connection for ste1824a/fxexg/APO_FXEXG_20090406_235735.txt.txt.
226 Transfer complete.
Process Completion time 20090406-23:57:58

/home/a_mstpap/clientoutbound/trigger/WEALTHTOUC_FXEXG_20090406_235736.txt.txt.TRG
archive clientoutbound dead.letter discard email fileArchive logs notify.lst notify.sav scripts_shared
Processing file /home/a_mstpap/clientoutbound/trigger/WEALTHTOUC_FXEXG_20090406_235736.txt.txt...
archive clientoutbound dead.letter discard email fileArchive logs notify.lst notify.sav scripts_shared
The trigger 220 DataExpress FTP Server ready.
331 Password required for ste2930z.
230 User WEALTHTOUCH - STE2930Z logged in to DataExpress.
200 PORT command successful.
150 Opening data connection 221 Goodbye.
Process Completion time 20090406-23:58:32
$ 
$ perl -lne '/^(\/|Process\b)/ && print' f7
/home/a_mstpap/clientoutbound/trigger/APO_FXEXG_20090406_235735.txt.txt.TRG
Process Completion time 20090406-23:57:58
/home/a_mstpap/clientoutbound/trigger/WEALTHTOUC_FXEXG_20090406_235736.txt.txt.TRG
Process Completion time 20090406-23:58:32
$ 
$

tyler_durden
# 4  
Old 04-09-2010
MySQL

You guys are the best..thank you!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 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

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

5. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

7. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

8. Shell Programming and Scripting

Search a string and append text after the string

Hi, I have a file like this... <o t="Batch" id="8410" p="/" g="32"> <a n="name"> <v s="DBBA1MM"/> </a> <a n="owner"> <v r="/Administrator"/> </a> <a n="rights"> <v s="95"/> </a> <a n="debugLevel"> <v s="3"/> </a> <a n="avsStoreLoc"> <v... (8 Replies)
Discussion started by: kesu2k
8 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

10. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies
Login or Register to Ask a Question