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
# 8  
Hi cmdcmd,
We are glad that you have solved your problem.

Please tell us how you solved your problem so that other people reading your thread can learn from your experience.

Note also that if you show us how you solved your problem, tell us what operating system you're using, and tell us what shell you're using; someone might be able to offer another solution that would work even better in your environment.

Cheers,
Don
# 9  
I'm a bit stumped by your "solution". In your original, unedited first post you had two (identical at the core) scripts working on the same input file, of which you claimed one showed satisfactory results, the other showed no output. That behaviour would not be explained by a non-*nix input text file.
This User Gave Thanks to RudiC For This Post:
# 10  
Quote:
Originally Posted by RudiC
I'm a bit stumped by your "solution". In your original, unedited first post you had two (identical at the core) scripts working on the same input file, of which you claimed one showed satisfactory results, the other showed no output. That behaviour would not be explained by a non-*nix input text file.
Hi RudiC,
I believe that with bash, the [[ string == pattern ]] comparison uses pathname pattern matching (rather than BRE or ERE matching), so having a trailing <CR> on the ends of the names stored in the file kept a pattern of *"{" that was looking for the last character to be a { didn't match when the last character was a <CR>. It would match when he set a variable to the correct value without the trailing <CR>.

There are lots of ways this issue could be fixed. I'm still hoping that cmdcmd will tell us what method he selected when he solved this problem.
# 11  
This doesn't care whether there is a <CR>, 0x0D, or not and puts it back if need be but removing them is easy.
Obviously performance depends on the size of the file and this does NOT allow for tabs and spaces at the start of each line containing a "{".

OSX 10.14.3, default bash terminal.
Code:
#!/bin/bash

printf "abc def{\x0D\x0Acdefg\x0D\x0Athis is a string\x0D\x0Afghh_hjhad_text{\x09text after brace with tab\x0D\x0A\x0D\x0A{\x0D\x0A{ text  at    end     only, (with spaces)!\x0D\x0Aabcd_123\x0D\x0Aend of file without brace\x0D\x0A" > /tmp/text
hexdump -C /tmp/text
echo "cat /tmp/text:"
echo ""

cat /tmp/text
echo "TEST FILE CREATION END, FILTER START!"
echo ""

# Working part...
while read -r line
do
    for (( n=0; n<=${#line}; n++ ))
    do
        if [ "${line:$n:1}" = "{" ]
        then
            echo "$line"
        fi
    done
done < /tmp/text > /tmp/lines
# End of working part!

echo "FILTER DONE!"
echo ""

hexdump -C /tmp/lines
echo ""
cat /tmp/lines

Resluts:
Code:
Last login: Sat Mar 16 23:21:49 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./left_brace.sh
00000000  61 62 63 20 64 65 66 7b  0d 0a 63 64 65 66 67 0d  |abc def{..cdefg.|
00000010  0a 74 68 69 73 20 69 73  20 61 20 73 74 72 69 6e  |.this is a strin|
00000020  67 0d 0a 66 67 68 68 5f  68 6a 68 61 64 5f 74 65  |g..fghh_hjhad_te|
00000030  78 74 7b 09 74 65 78 74  20 61 66 74 65 72 20 62  |xt{.text after b|
00000040  72 61 63 65 20 77 69 74  68 20 74 61 62 0d 0a 0d  |race with tab...|
00000050  0a 7b 0d 0a 7b 20 74 65  78 74 20 20 61 74 20 20  |.{..{ text  at  |
00000060  20 20 65 6e 64 20 20 20  20 20 6f 6e 6c 79 2c 20  |  end     only, |
00000070  28 77 69 74 68 20 73 70  61 63 65 73 29 21 0d 0a  |(with spaces)!..|
00000080  61 62 63 64 5f 31 32 33  0d 0a 65 6e 64 20 6f 66  |abcd_123..end of|
00000090  20 66 69 6c 65 20 77 69  74 68 6f 75 74 20 62 72  | file without br|
000000a0  61 63 65 0d 0a                                    |ace..|
000000a5
cat /tmp/text:

abc def{
cdefg
this is a string
fghh_hjhad_text{    text after brace with tab

{
{ text  at    end     only, (with spaces)!
abcd_123
end of file without brace
TEST FILE CREATION END, FILTER START!

FILTER DONE!

00000000  61 62 63 20 64 65 66 7b  0d 0a 66 67 68 68 5f 68  |abc def{..fghh_h|
00000010  6a 68 61 64 5f 74 65 78  74 7b 09 74 65 78 74 20  |jhad_text{.text |
00000020  61 66 74 65 72 20 62 72  61 63 65 20 77 69 74 68  |after brace with|
00000030  20 74 61 62 0d 0a 7b 0d  0a 7b 20 74 65 78 74 20  | tab..{..{ text |
00000040  20 61 74 20 20 20 20 65  6e 64 20 20 20 20 20 6f  | at    end     o|
00000050  6e 6c 79 2c 20 28 77 69  74 68 20 73 70 61 63 65  |nly, (with space|
00000060  73 29 21 0d 0a                                    |s)!..|
00000065

abc def{
fghh_hjhad_text{    text after brace with tab
{
{ text  at    end     only, (with spaces)!
AMIGA:amiga~/Desktop/Code/Shell> _

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
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...... Shell Programming and Scripting
6
Shell Programming and Scripting
Curly braces in sed
tostay2003
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'... Shell Programming and Scripting
13
Shell Programming and Scripting
How do I pull the value between curly braces?
Scottie1954
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...... UNIX for Dummies Questions & Answers
7
UNIX for Dummies Questions & Answers
Curly braces assigned to variables
njks68
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...... Shell Programming and Scripting
1
Shell Programming and Scripting
Use of curly braces with variables
abhinavsinha
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...... Shell Programming and Scripting
2
Shell Programming and Scripting

Featured Tech Videos