Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Check string end with curly braces


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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; 03-15-2019 at 11:10 PM..
# 2  
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  
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  
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  
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:
# 7  
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

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

When curly braces needed?

Hello, i was trying to find get a command to list duplicated files so i tried ls dir1 dir2 | awk '{x++}' and it didnt work. After a bit of searching online i found that it works without the curly braces ls dir1 dir2 | awk 'x++' I thought the curly braces were needed in awk so... (6 Replies)
Discussion started by: andy391791
6 Replies

2. Shell Programming and Scripting

Curly braces in sed

Hi, I have below command in one of the script. Can you please let me know what does the curly braces do over here \{1,\}. The remaining part of the code atleast I am able to understand. sed -n 's/.*\-\()\{1,\}\)\-.*/\1/p' (13 Replies)
Discussion started by: tostay2003
13 Replies

3. Shell Programming and Scripting

How to remove newline, tab, spaces in curly braces.. :( Pls Help?

Hi Everyone, in the below "xyz (Exception e)" part... after the curly braces, there is a new line and immediately few tabs are present before closing curly brace. xyz (Exception e) { } note: there can be one or more newlines between the curly braces. My desired output should be ... (6 Replies)
Discussion started by: NY_777
6 Replies

4. Shell Programming and Scripting

** EMERGENCY ** Having trouble with curly braces.. :( Pls Help

Hi Everyone, in the below "xyz (Exception e)" part... after the curly braces, there is a new line and immediately few tabs are present before closing curly brace. xyz (Exception e) { } note: there can be one or... (1 Reply)
Discussion started by: NY_777
1 Replies

5. UNIX for Dummies Questions & Answers

How do I pull the value between curly braces?

Hi everyone, I've got a file that looks like this: uid{508}pid{22224}pname{/PPROGRAM/pprgramx -profile:LIVE -serv:as ... I want to pull the value of pid between the curly braces, or 22224 in this example. pid is always the second pair of curly braces, but the length of the number is... (7 Replies)
Discussion started by: Scottie1954
7 Replies

6. Shell Programming and Scripting

tar --exclude with curly braces

I'm having trouble understanding the exclude option in tar. From some web sites, it seems one is able to exclude several strings by enclosing them in curly brackets. However it seems to be "random" what gets excluded when using the curlies. I've been using the exclude-from=myfile option in a... (12 Replies)
Discussion started by: majest
12 Replies

7. Shell Programming and Scripting

sed in windows does not parse curly braces

Hi everyone: I'm stuck at this point, could you guys please give me some hints about what I am doing wrong in the following script, I'm using sed for windows: sed ^"$ {^ a^ STRINGTABLE DISCARDABLE^ BEGIN^ #define CLIENT_MODULE, "%CLIENT_MODULE%"^ #define CLIENT_ID, "%CLIENT_ID%"^... (1 Reply)
Discussion started by: edgarvm
1 Replies

8. Shell Programming and Scripting

find -regex not recognizing curly braces

Must be a bug or something. Whether I escape them or not, it will not work. No matter what I set the minimum and maximum to nothing gets caught. For instance: find / -regex "/.{0, 50}.*" -maxdepth 1 or find / -regex "/.\{0, 50\}.*" -maxdepth 1 should pretty much catch everything residing within... (4 Replies)
Discussion started by: stevensw
4 Replies

9. Shell Programming and Scripting

Curly braces assigned to variables

Hi, Im pretty new to Unix. I came across a script which was using PLSQL inside a script and there was an unusual thing mentioned. there was a variable assigned as P_CUR=${1} and one more as V_TAGFILE="$1" Couldnt find the difference. Also the variables were used in PLSQL... (1 Reply)
Discussion started by: njks68
1 Replies

10. Shell Programming and Scripting

Use of curly braces with variables

Hi, I am new to shell scripting.I have worked somewhat with Perl though. I am not able to find what the second line does and how does it do. <code> FP_RUNNING=`service filepool status` FP_RUNNING=${FP_RUNNING%% *} <\code> After the first line,the variable FP_RUNNING stores '1 FilePool... (2 Replies)
Discussion started by: abhinavsinha
2 Replies

Featured Tech Videos