Check string end with curly braces


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
Check string end with curly braces

[UPDATE]

file.txt

Code:
apple
apples{
applepicture
apple9
apple cake{
abple
apple_and_cake
appleapple
apple
apple(

and my script
Code:
while read line; do
	if [[ "$line" == *{ ]]; then
		echo "$line"
	fi
done <file.txt
read

My purpose is to display lines that end with {
- if I want to display lines start with, I would write:
Code:
if [[ "$line" == "apple"* ]]; then

(It displays results)
- To display lines content a string, I would write:
Code:
 if [[ "$line" == *"9"* ]]; then

(It display results)
- However, to display lines end with, I wrote:
Code:
if [[ "$line" == "{"* ]]; then

(But IT DOES NOT DISPLAY RESULT)
. I supposed It would print out
Code:
           apples{
           apple cake{

Moderator's Comments:
Mod Comment Please use CODE tags when displaying ALL sample input, sample output, and code segments.

Please DO NOT go back and edit posts after other unix.com members have commented on your posts. It makes it impossible to figure out what the responses meant when the text they were responding to is no longer present! Instead, add a new post with your new comments and corrections.

Last edited by Don Cragun; 1 Week Ago at 10:10 PM..
# 2  
Old 1 Week Ago
Help me out - I don't see a difference between the two scripts, nor in their output - it's identical. So - please show the entire picture. Any output redirection upfront?
# 3  
Old 1 Week Ago
Please show us the output from the command:
Code:
od -bc file.txt

My guess would be that the file has DOS style line terminators and there is an invisible <carriage-return> character following the <open-brace> character before the <newline> character that is keeping the line read from the file from matching.
# 5  
Old 1 Week Ago
Please show us the output from the command I asked you to run in post #3 in this thread. Without the information that output will provide, we can't explain what is causing the problem you are describing.
# 6  
Old 1 Week Ago
Quote:
Originally Posted by cmdcmd
[UPDATE]

file.txt

Code:
apple
apples{
applepicture
apple9
apple cake{
abple
apple_and_cake
appleapple
apple
apple(

and my script
Code:
while read line; do
	if [[ "$line" == *{ ]]; then
		echo "$line"
	fi
done <file.txt
read

My purpose is to display lines that end with {
- if I want to display lines start with, I would write:
Code:
if [[ "$line" == "apple"* ]]; then

(It displays results)
- To display lines content a string, I would write:
Code:
 if [[ "$line" == *"9"* ]]; then

(It display results)
- However, to display lines end with, I wrote:
Code:
if [[ "$line" == "{"* ]]; then

(But IT DOES NOT DISPLAY RESULT)
. I supposed It would print out
Code:
           apples{
           apple cake{

Moderator's Comments:
Mod Comment Please use CODE tags when displaying ALL sample input, sample output, and code segments.

Please DO NOT go back and edit posts after other unix.com members have commented on your posts. It makes it impossible to figure out what the responses meant when the text they were responding to is no longer present! Instead, add a new post with your new comments and corrections.
Note that [[ "$line" == "{"* ]] will match lines starting with {; not lines ending with { unless the only character on the line is {.
This User Gave Thanks to Don Cragun For This Post:
cmdcmd (1 Week Ago)
# 7  
Old 1 Week Ago
Sorry for my inconvenience post that make you not understanding. I will be careful to read the guideline before post a good quality question in the next posts.

However, I solved it.

The problem is CF LF on each line on notepad++. That is the reason why I cannot find line at end with {

Thank you Don Cragun and RudiC to moderate and reply me.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
When curly braces needed? andy391791 Shell Programming and Scripting 6 05-12-2016 12:49 PM
Curly braces in sed tostay2003 Shell Programming and Scripting 13 06-25-2015 09:12 AM
How to remove newline, tab, spaces in curly braces.. :( Pls Help? NY_777 Shell Programming and Scripting 6 10-01-2014 08:34 AM
** EMERGENCY ** Having trouble with curly braces.. :( Pls Help NY_777 Shell Programming and Scripting 1 10-01-2014 03:34 AM
How do I pull the value between curly braces? Scottie1954 UNIX for Dummies Questions & Answers 7 07-08-2013 06:34 AM
Search a string in a text file and add another string at the end of line suryanarayana Shell Programming and Scripting 5 05-27-2013 07:21 AM
Remove lines between the start string and end string including start and end string Python Dabheeruz Shell Programming and Scripting 1 02-15-2013 11:40 AM
tar --exclude with curly braces majest Shell Programming and Scripting 12 08-09-2012 12:06 PM
sed in windows does not parse curly braces edgarvm Shell Programming and Scripting 1 11-11-2011 10:39 AM
Need to check date at the end venkatesht UNIX for Dummies Questions & Answers 1 05-17-2011 12:00 AM
find -regex not recognizing curly braces stevensw Shell Programming and Scripting 4 05-16-2011 12:15 AM
Curly braces assigned to variables njks68 Shell Programming and Scripting 1 06-11-2010 06:42 AM
Appending string, variable to file at the start and string at end Vaddadi Shell Programming and Scripting 4 03-24-2010 01:31 PM
Use of curly braces with variables abhinavsinha Shell Programming and Scripting 2 03-05-2008 06:57 AM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 10:14 PM