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
egorgry
  • 2,871
  • 2
  • 23
  • 21

3 Answers3

4

You can try this sed command:

$ sed '/[ \t]GROUP/ s/{*$/ {/' scst.conf.test > greg.scst.out
Khaled
  • 36,533
  • 8
  • 72
  • 99
2

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

sed 's|\([ \t]GROUP.*\)[^{]$|\1 {|' yourfile
Selman Ulug
  • 161
  • 4
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.

webtoe
  • 1,976
  • 11
  • 12