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
return previous line for pattern match braindrain UNIX for Dummies Questions & Answers 4 12-08-2008 05:17 PM
how to go previous line in vim useless79 UNIX for Advanced & Expert Users 2 09-16-2007 08:10 AM
replace [previous] line grossgermany Shell Programming and Scripting 10 07-29-2007 09:40 AM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 08:04 AM
Return status of all previous runs mpang_ Shell Programming and Scripting 4 06-27-2006 02:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-17-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
return the previous line

Hello friends ,

I am doing the following command, but it is not wise to all files.
Code:
for temp in `find ./CSV/ -name  "*.txt"`
do
          sed -n -e 'N; /*Main End/p' $temp
done
Its give me the correct output for some files , but not for all files.
I mean some files contains the string *Main End , But it wont return me any value . But In some files it contains the exact *Main End pattern , it returns me the previous line as usual.

Pls help..

I am using Solaris 6.0
  #2 (permalink)  
Old 12-17-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
I think you misunderstand /*Main End/ as a regex.
Code:
/Main End$/ = Main End at the end of a line
/.*Main End/ = one or more of any character before Main End occurs  could be
   in the middle or at the end
The sed syntax is fine, it is your search expression causing your probelm.
  #3 (permalink)  
Old 12-17-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by jim mcnamara View Post
I think you misunderstand /*Main End/ as a regex.
Code:
/Main End$/ = Main End at the end of a line
/.*Main End/ = one or more of any character before Main End occurs  could be
   in the middle or at the end
The sed syntax is fine, it is your search expression causing your probelm.
Thanks for the reply.
But I opened in vi editor . And when I looked with the vi option
set list. It seems to be both same .

Ok. can you Please suggest me a R.E here for search the below
starting with a * follwing Main End.

Thank you in advance..
  #4 (permalink)  
Old 12-18-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Strange output

Quote:
Originally Posted by user_prady View Post
Thanks for the reply.
But I opened in vi editor . And when I looked with the vi option
set list. It seems to be both same .

Ok. can you Please suggest me a R.E here for search the below
starting with a * follwing Main End.

Thank you in advance..
I ve two files looks as follows
file1
Code:
*Comment Frame 641 at 666.667 us
000000,CB1F,0,0,0,0,1,0,1
*Main End
file 2
Code:
000000,0000,0,0,2,0,0,0,0
*Comment Frame 
5,7E3D,0,0,0,0,1,0,1
*Main End
But when I using the command for both file
Code:
sed -n -e 'N; /\*Main End/p' file1
it should return me the line before The pattern *Main End

But it wont

But in case of file2 its working ,

Please need help urgently..

Last edited by user_prady; 12-18-2007 at 01:18 AM..
  #5 (permalink)  
Old 12-18-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try:
sed -n -e '/\*Main End/{g;p;q;};h' file1

This returns only the line before the Main End line. Do you really need that Main End line as well? If so try this one:
sed -n -e '/\*Main End/{H;g;p;q;};h' file1
  #6 (permalink)  
Old 12-18-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by Perderabo View Post
Try:
sed -n -e '/\*Main End/{g;p;q;};h' file1

This returns only the line before the Main End line. Do you really need that Main End line as well? If so try this one:
sed -n -e '/\*Main End/{H;g;p;q;};h' file1
Thanks for the reply.
I am afraid, It wont return anything either of these..

I need only the previous line..
Closed Thread

Bookmarks

Tags
linux, linux commands

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 05:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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