Searching for lines ending with }


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for lines ending with }
# 1  
Old 03-10-2009
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  
Old 03-10-2009
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  
Old 03-10-2009
Quote:
Originally Posted by BootComp
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  
Old 03-10-2009
Quote:
Originally Posted by Franklin52
Use the -v option of grep:

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

Regards
Nope this does not give any output either. Smilie
# 5  
Old 03-10-2009
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 07:07 AM..
# 6  
Old 03-10-2009
Could it be that the lines do not end with exactly the '}' char? Try this:
Code:
$ grep -Ev '}\s*$' file

# 7  
Old 03-10-2009
Quote:
Originally Posted by gauravacl
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? Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove lines ending with a certain character

I have a file of a content like this: abc_bla -def 800 abc_bla -def 802 abc_bla -def 804 abc_bla -def 806 abc_bla -def 808 abc_bla -def 810 abc_bla -def 812 abc_bla -def 814 ... abc_bla -def 898 abc_bla -def 900 abc_bla -def 902 abc_bla -def 904 ... abc_bla -def 990 abc_bla -def... (7 Replies)
Discussion started by: maya3
7 Replies

2. UNIX for Dummies Questions & Answers

General find /grep question: files with lines ending in r

I am trying to find files that have lines in them that end in an r. I have been able to locate files by using the following command: find . -type f -name "*RECORDS"| xargs grep -l r$ However, I now want to find files that don't end in r anywhere. That means that no sentences or lines in... (9 Replies)
Discussion started by: newbie2010
9 Replies

3. Shell Programming and Scripting

Find out if multiple files have lines ending with"r"

I am trying to find out which files in a group of files have lines ending in r. What I have is this: cat /tmp/*RECORDS| if grep r$>/dev/null; then echo "yes";else echo"no";fi Records is more than one file. There are the following files TEST-RECORDS /volume/testing /volume/programs ... (2 Replies)
Discussion started by: newbie2010
2 Replies

4. Shell Programming and Scripting

Remove certain lines from file based on start of line except beginning and ending

Hi, I have multiple large files which consist of the below format: I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one. Any help would be greatly appreciated. (10 Replies)
Discussion started by: nwalsh88
10 Replies

5. Shell Programming and Scripting

Delete all lines ending with /

I have a text file with contents given below: file:///About/ file:///About/accessibility.html file:///About/disclaimer.html file:///About/disclaimer.html#disclaimer file:///About/glance/contact_info.html file:///books/ file:///bookshelf/br.fcgi?book=helppubmed&part=pubmedhelp... (6 Replies)
Discussion started by: shoaibjameel123
6 Replies

6. UNIX for Dummies Questions & Answers

how to remove lines ending with '*'

I have a file where some lines end with '*'. I would like to remove those lines ending with '*'. inFile: a b* c d*outFile: a cThank you (7 Replies)
Discussion started by: jdhahbi
7 Replies

7. Shell Programming and Scripting

Concatenating lines ending with '+' using awk

Hi, I have an ASCII text file where some of the lines are ending with '+' character. I have to concatenate the next successive line with those lines having the trailing '+' char by removing that char. The below awk code has some problems to do this task: awk '{while(sub(/\+$/,"")) {... (12 Replies)
Discussion started by: royalibrahim
12 Replies

8. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

9. Shell Programming and Scripting

Deleting lines ending with . from a file

HI I'm looking to delete lines ending with .tk from below data file --------- abc.tk mgm.tk dtk mgmstk ------ I have written below code ---- sed '/.tk *$/d' dat_file.txt > temp.txt ---- But its deleting all the lines ending with tk. I need to delete only the lines ending .tk my... (5 Replies)
Discussion started by: shekhar_v4
5 Replies

10. Solaris

removing particular lines ending with a .cnt extension in a text file

I have a text file with rows of information (it is basically a ls command information(o/p from ls command)) I need to remove the lines ending with a .cnt extension and keep the lines ending with .zip extension, how to accomplish this. I also only need the date,size and name of the file from every... (2 Replies)
Discussion started by: ramky79
2 Replies
Login or Register to Ask a Question