The UNIX and Linux Forums  


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
lines searching >> neverhood Shell Programming and Scripting 2 01-18-2009 07:39 AM
searching and storing unknown number of lines based on the string with a condition swamymns Shell Programming and Scripting 7 05-13-2008 02:02 AM
removing particular lines ending with a .cnt extension in a text file ramky79 SUN Solaris 2 03-03-2008 05:17 AM
Delete lines ending in "_;" using sed turbulence Shell Programming and Scripting 12 01-17-2008 06:51 PM
sed searching across lines miechu Shell Programming and Scripting 11 10-03-2006 05:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-10-2009
BootComp BootComp is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 6
Searching for lines ending with }

I'm trying to search for lines ending with "}" with the following command but am not getting any output.

Code:
grep '\}$'  myFile.txt

I actually want to negate this (i.e. lines not ending with "}"), but I guess that should be easier once I find the command that finds it?
  #2 (permalink)  
Old 03-10-2009
milhan milhan is offline
Registered User
  
 

Join Date: Oct 2002
Location: /home
Posts: 133
this should do the work (put it inside a script) :


Code:
#!/bin/ksh

file=$1

typeset -i lineno=0

cat $file |
while read line
do
  lineno=lineno+1
  nline="${line%\}}"

  if [ "$nline" != "$line" ]
  then
    echo "$lineno ends in }"
  fi
done

  #3 (permalink)  
Old 03-10-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Quote:
Originally Posted by BootComp View Post
I'm trying to search for lines ending with "}" with the following command but am not getting any output.

Code:
grep '\}$'  myFile.txt

I actually want to negate this (i.e. lines not ending with "}"), but I guess that should be easier once I find the command that finds it?
Use the -v option of grep:


Code:
grep -v '}$' myFile.txt

Regards
  #4 (permalink)  
Old 03-10-2009
BootComp BootComp is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 6
Quote:
Originally Posted by Franklin52 View Post
Use the -v option of grep:


Code:
grep -v '}$' myFile.txt

Regards
Nope this does not give any output either.
  #5 (permalink)  
Old 03-10-2009
gauravacl gauravacl is offline
Registered User
  
 

Join Date: Jan 2009
Location: India
Posts: 17
Hi ,

Though Franklin's option works may be you can also try this

awk '{if($0~"}$"){print $0}}' <filename>

Hope this helps

Last edited by gauravacl; 03-10-2009 at 06:07 AM..
  #6 (permalink)  
Old 03-10-2009
BootComp BootComp is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 6
Quote:
Originally Posted by gauravacl View Post
Hi ,

Try this

awk '{if($0~"}$"){print $0}}' <filename>

Hope this helps
Thanks. That did the trick. But can't seem to figure out how to negate this now?

BTW still can't understand why grep doesn't match this?
  #7 (permalink)  
Old 03-10-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,941
Could it be that the lines do not end with exactly the '}' char? Try this:
Code:
$ grep -Ev '}\s*$' file

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 01:06 PM.


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