Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Check string end with curly braces Post 303032410 by wisecracker on Saturday 16th of March 2019 07:35:51 PM
Old 03-16-2019
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> _

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
subst(n)						       Tcl Built-In Commands							  subst(n)

__________________________________________________________________________________________________________________________________________________

NAME
subst - Perform backslash, command, and variable substitutions SYNOPSIS
subst ?-nobackslashes? ?-nocommands? ?-novariables? string _________________________________________________________________ DESCRIPTION
This command performs variable substitutions, command substitutions, and backslash substitutions on its string argument and returns the fully-substituted result. The substitutions are performed in exactly the same way as for Tcl commands. As a result, the string argument is actually substituted twice, once by the Tcl parser in the usual fashion for Tcl commands, and again by the subst command. If any of the -nobackslashes, -nocommands, or -novariables are specified, then the corresponding substitutions are not performed. For example, if -nocommands is specified, command substitution is not performed: open and close brackets are treated as ordinary characters with no special interpretation. Note that the substitution of one kind can include substitution of other kinds. For example, even when the -novariables option is speci- fied, command substitution is performed without restriction. This means that any variable substitution necessary to complete the command substitution will still take place. Likewise, any command substitution necessary to complete a variable substitution will take place, even when -nocommands is specified. See the EXAMPLES below. If an error occurs during substitution, then subst will return that error. If a break exception occurs during command or variable substi- tution, the result of the whole substitution will be the string (as substituted) up to the start of the substitution that raised the excep- tion. If a continue exception occurs during the evaluation of a command or variable substitution, an empty string will be substituted for that entire command or variable substitution (as long as it is well-formed Tcl.) If a return exception occurs, or any other return code is returned during command or variable substitution, then the returned value is substituted for that substitution. See the EXAMPLES below. In this way, all exceptional return codes are "caught" by subst. The subst command itself will either return an error, or will complete successfully. EXAMPLES
When it performs its substitutions, subst does not give any special treatment to double quotes or curly braces (except within command sub- stitutions) so the script set a 44 subst {xyz {$a}} returns "xyz {44}", not "xyz {$a}" and the script set a "p} q {r" subst {xyz {$a}} returns "xyz {p} q {r}", not "xyz {p} q {r}". When command substitution is performed, it includes any variable substitution necessary to evaluate the script. set a 44 subst -novariables {$a [format $a]} returns "$a 44", not "$a $a". Similarly, when variable substitution is performed, it includes any command substitution necessary to retrieve the value of the variable. proc b {} {return c} array set a {c c [b] tricky} subst -nocommands {[b] $a([b])} returns "[b] c", not "[b] tricky". The continue and break exceptions allow command substitutions to prevent substitution of the rest of the command substitution and the rest of string respectively, giving script authors more options when processing text using subst. For example, the script subst {abc,[break],def} returns "abc,", not "abc,,def" and the script subst {abc,[continue;expr {1+2}],def} returns "abc,,def", not "abc,3,def". Other exceptional return codes substitute the returned value subst {abc,[return foo;expr {1+2}],def} returns "abc,foo,def", not "abc,3,def" and subst {abc,[return -code 10 foo;expr {1+2}],def} also returns "abc,foo,def", not "abc,3,def". SEE ALSO
Tcl(n), eval(n), break(n), continue(n) KEYWORDS
backslash substitution, command substitution, variable substitution Tcl 7.4 subst(n)
All times are GMT -4. The time now is 12:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy