SED to touch some lines and leave others

I have a log file that looks like this

#blah blah comment
1234567890 INFO aaaaa
1234567891 DEBUG bbbbb

This
sed 's/^/[/; s/ /] /1'

Open in new window

places the first item in square brackets []  on all lines, including the comments.

Need a sed or awk script to place the first item in square brackets [] but not to change the comment lines starting with #.
The end result should be

#blah blah comment
[1234567890] INFO aaaaa
[1234567891] DEBUG bbbbb

Nothing I do seems to work.
LVL 34
shalomcCTOAsked:
Who is Participating?
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Try this:

awk '! /^#/ {gsub($1,"["$1"]")} {print}' your_logfile
0
 
woolmilkporcCommented:
sed 's/\(^[^#][^ ]*\)/[\1]/'  logfile
0
 
shalomcCTOAuthor Commented:
thanks guys, EE rules
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.