The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for a string and copy the entire line forumthreads UNIX for Dummies Questions & Answers 3 06-29-2009 07:29 AM
How to search file content satimis Linux 4 10-22-2008 12:46 AM
shell script to search a string and delete the content vic_mnnit Shell Programming and Scripting 6 10-21-2008 09:00 AM
Search File content. elenatec UNIX for Dummies Questions & Answers 3 09-04-2008 11:53 AM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 08:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2008
pankajp pankajp is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 6
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
  #2 (permalink)  
Old 11-17-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question

Are you trying to ask?

file1=

blah
blah
ABC
123
456
789
DEF
yech
yech

Thus, search file1 to copy from ABC to DEF to file2
ABC
123
456
789
DEF
  #3 (permalink)  
Old 11-17-2008
pankajp pankajp is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 6
Yes. exactly
this is my result what u have got in second file

Please help me to get that.
  #4 (permalink)  
Old 11-17-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Probably easier ways, but...

I would guess that there is a simpler solution with awk, but the following code uses sed, tr and grep -- three of my favorites -- to solve this.

Code:
> cat file73
blah
blah
ABC
123
456
789
DEF
yech
yech


> sed "s/^ABC/#ABC/" <file73 | sed "s/DEF$/DEF#/" | tr "\n" "~" | tr "#" "\n" | grep "^ABC" | tr "~" "\n"
ABC
123
456
789
DEF
  #5 (permalink)  
Old 11-17-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

wouldn't

Code:
sed -n '/^ABC/,/^DEF/p' file
be simpler? This tells sed to output only the lines between lines starting with ABC and lines starting with DEF.

HTH Chris
  #6 (permalink)  
Old 11-18-2008
pankajp pankajp is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 6
Hi

Hi All,

Thanks for helping me but I am trying to search date. I mean my first string is like [11/10/08 8:43:58:610 EST] and second is [11/10/08 8:44:44:340 EST] and I want data between these tow lines(OR Strings).

I have tried your commands for the strings its working fine but please help me in above case.

THANKS
  #7 (permalink)  
Old 11-18-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Have you tried the sed command above? It should be something like:

Code:
sed -n '/[11/10/08 8:43:58:610 EST]/,/[11/10/08 8:44:44:340 EST]/p' file > newfile
Regards
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0