INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Using $ in search string

Using $ in search string

(OP)
I have a file format that has blank lines within the record, and uses $$$$ as a record end.
Thus \n$$$$\n is the end of the record, the the next character starts the next record.
I have made several attempts to parse this with awk,
RS = "\n$$$$\n" does not work
RS = /\n\$\$\$\$\n/ does not work
and several other options do not work.
Now the thing that makes this strange is that if I go into the file and do an edit
$$$$ -> ####, i.e. changing the 4 $ to 4 #, the following value for RS works perfectly:
RS="\n####\n"

It would appear that the fact that the $ is the end of match marker is getting in the way here, but it would seem that it should be escaped with the \$ and the character just looked at as $, but it is not.
In one sense I have solved the problem by editing the file first and then processing it, but I would like to know if anyone has an idea of what is going on and what RS value I should be using to get the desired result.
Thanks.
Gary

RE: Using $ in search string

Hi

CODE

awk -vRS='\n\\$\\$\\$\\$\n' 1 /input/file

# or

awk 'BEGIN{RS="\n\\$\\$\\$\\$\n"}1' /input/file 
You assign a string to RS, which will be interpreted as regular expression. In regular expression you have to escape the literal dollar sign ( $ ) with a backslash ( \ ). In string you have to escape regular backslash with a backslash.

Feherke.
http://feherke.github.com/

RE: Using $ in search string

(OP)
Feherke,
Thanks for the solution, it worked perfectly and more importantly thank you for the discussion of what the issue in the problem was. I had not been aware that the RS string was interpreted as a regular expression when given as a string. I had even tried RS = /\n\$\$\$\$\n/ with no luck - which I would have thought was the same, but it to did not work, but probably would have had it been double escaped. I should note that this is being done in an awk script since subsequent processing is more complex, but this was the key.
Thanks again.
Gary

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close