1

This is probably easy and something is not clicking for me and my lack of coffee right now. I have a file with multiple lines that begin with a tab then the word GROUP something {

Some of these lines for whatever reason drop the curly bracket under some conditions. The quick fix is to use sed/awk to append the curly bracket to that line but not lines where the bracket already exist. I'm halfway there with but as you can see this will append the open curly bracket to every line that begins with a tab and GROUP.

sed '/[ \t]GROUP/ s/$/ {/' scst.conf.test > greg.scst.out
4

You can try this sed command:

$ sed '/[ \t]GROUP/ s/{*$/ {/' scst.conf.test > greg.scst.out
  • These all worked but this one made the most sense to me. Thanks. – egorgry Mar 8 '12 at 15:54
2

Checking GROUP something without { and back referencing it then replacing with \1 {.

sed 's|\([ \t]GROUP.*\)[^{]$|\1 {|' yourfile
2

With the following test file as test.txt:

    GROUP blah {
    GROUP blah {
    GROUP blah
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {

The following sed script does the business:

sed -r 's/\tGROUP(.*)[^{]$/&{/' test.txt

With the output looking like this:

    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {
    GROUP blah {

Is that correct? What it does is look for lines which have tab->GROUP any characters but don't have { at the end. Replaces it with the matched line (that is what the & does) and appends a { afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.