Search and copy to a new file-Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and copy to a new file-Help
# 1  
Old 04-28-2009
Search and copy to a new file-Help

Hi All,

Code:
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "CWD" dms-imrm/Delasco_Invoices_DayForward_Scan" 250 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PWD" 257 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "CWD Private" 250 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PWD" 257 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "DELE PRINV00676516.pdf" 550 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PASV" 227 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676516.pdf" 226 208723
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "DELE PRINV00676517.pdf" 550 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PASV" 227 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676517.pdf" 226 135755
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "DELE PRINV00676518.pdf" 550 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PASV" 227 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676518.pdf" 226 143027
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "DELE PRINV00676519.pdf" 550 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PASV" 227 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676519.pdf" 226 280986
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "DELE PRINV00676520.pdf" 550 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "PASV" 227 -
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676520.pdf" 226 200884
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:29 -0400] "QUIT" 221 -


I need a script which searches all the files which are uploaded from the remote server to this server to a new file. Ie the fourth word/field in the above list, if it is STOR that means it’s an uploaded one. So here I have to search for “imrm/Delasco_Invoices_DayForward_Scan” first and whatever files uploaded with its size to be moved to a new file.

In a better way: I need a new file which have the following details only… it should stop copying the lines once "Quit" is found.

Code:
imrm/Delasco_Invoices_DayForward_Scan
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676516.pdf" 226 208723
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676517.pdf" 226 135755
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676518.pdf" 226 143027
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676519.pdf" 226 280986
  server16.na.in.com UNKNOWN ftpuser [27/Apr/2009:11:08:24 -0400] "STOR PRINV00676520.pdf" 226 200884


Is that very difficult? i dont know how to go. It would be great help if some one can help me in this.

Last edited by Tuxidow; 04-28-2009 at 07:09 AM..
# 2  
Old 04-28-2009
One way:

Code:
awk '/imrm\/Delasco_Invoices_DayForward_Scan/{
  print "imrm/Delasco_Invoices_DayForward_Scan"
  f=1
}
/QUIT/{exit}
f && /STOR/' file > newfile

# 3  
Old 04-28-2009
issue resolved... thanks a lottt SmilieSmilie
# 4  
Old 04-28-2009
Inorder to search and find multiple occurrences of this how should i go?

Say if i have Delasco_Invoices_DayForward_Scan details a few more time. how can i loop this?
# 5  
Old 04-28-2009
Quote:
Originally Posted by Tuxidow
Inorder to search and find multiple occurrences of this how should i go?

Say if i have Delasco_Invoices_DayForward_Scan details a few more time. how can i loop this?
Replace the exit command and set the flag to 0.

Code:
 awk '/imrm\/Delasco_Invoices_DayForward_Scan/{
  print "imrm/Delasco_Invoices_DayForward_Scan"
  f=1
}
/QUIT/{f=0}
f && /STOR/' file > newfile

# 6  
Old 04-28-2009
Excellent.. A great help.... Thanks a lot for the Swift Reply.. :-) Could you please explain the code for me. so that i will get better understanding of it..

Last edited by Tuxidow; 04-28-2009 at 04:13 PM..
# 7  
Old 04-29-2009
Quote:
Originally Posted by Tuxidow
Excellent.. A great help.... Thanks a lot for the Swift Reply.. :-) Could you please explain the code for me. so that i will get better understanding of it..
Code:
awk '/imrm\/Delasco_Invoices_DayForward_Scan/{
  print "imrm/Delasco_Invoices_DayForward_Scan"
  f=1

If the line contains the regexp print the header and assign 1 to the variable f.

Code:
/QUIT/{f=0}

If the line contains QUIT unset the variable f.

Code:
f && /STOR/' file > newfile

If the variable f is set and the line contains the word STOR print the line.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and Copy Files

Hi All Need your help, I am looking for a script to search for files with specific extension as .log and then copy the latest one to a different folder. Here is the scenario /dev/abc/xyz/a_2_122920131.log /dev/abc/xyz/a_2_123020131.log /dev/abc/xyz/b_2_12302013.log... (2 Replies)
Discussion started by: jimmun
2 Replies

2. Shell Programming and Scripting

Search the pattern and copy in to the file

my qn is i have one file hex.txt.it contains some junk data and some hexa valueslike hex.txt sdfjhjkh 0x1233jkfhgjfhgajk;gha 0xacdd jkgahfjkgha;sjghajklgha;gh aghfjkgh;a 0xccc jhfjkhsd ox23cd 0x456 jkhdfjhjkafh like this now iwant a script like to separate the hex values and paste into the... (12 Replies)
Discussion started by: siva.hardwork
12 Replies

3. Shell Programming and Scripting

search a word and copy the file

Hi need help with a script or command My requirement is - I need to do a "ls -ltr tcserver*.syslog" files in /tmp, direct the output to a file ls -ltr tcserv*.syslog | grep "Jan 31" | awk '{printf "\n" $9}' > jandat.logs -Then open each file in above list and search for string/word,... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

5. Shell Programming and Scripting

Search multiple strings on a file and copy the string next to it

I tried awk for this, but failed <or my code is not correct? I dont know>. Can anyone help me on this? ---------- Post updated at 08:34 PM ---------- Previous update was at 08:29 PM ---------- my working file looks like this: <empty> <empty> <empty> NAME :ABC AGE :15 GENDER... (6 Replies)
Discussion started by: kingpeejay
6 Replies

6. Shell Programming and Scripting

Search, copy and paste

Can i search in a file for more than one string at a time? And copy the next string after that and paste it in column style? Is it possible? Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

7. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies

8. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

9. UNIX for Advanced & Expert Users

File extension search and copy

Hi need to know if we can write a shell script to find files for a particular format;s ie both .csv and .txt in a particular folder and then copy them to a new folder on a dialy basis. Does anyone know how this can be accomplished? Thanks, Sandeep (20 Replies)
Discussion started by: bsandeep_80
20 Replies

10. Shell Programming and Scripting

Search for strings & copy to new file

Hi All, I am just learning shell programming, I need to do the following in my shell script. Search a given log file for two\more strings. If the the two\more strings are found then write it to a outputfile else if only one of the string is found, write the found string in one output... (2 Replies)
Discussion started by: amitrajvarma
2 Replies
Login or Register to Ask a Question