LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-26-2011, 04:15 AM   #1
corone
Member
 
Registered: Jul 2009
Posts: 46

Rep: Reputation: 1
How to express built-In variable, RS in awk command


I am going to separate records with the string, "[J.System Info]" in awk command.

Both of the following expressions don't work well.
Code:
RS = "[J.System Info]"
(or)
RS = "[\J\.System Info\]"

Last edited by corone; 04-26-2011 at 04:17 AM.
 
Old 04-26-2011, 04:25 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
In gawk, the field and record separators are either single characters, or treated as regular expressions. In the above, the [] around the string means you're setting it to a list of single characters, any of which will match.

You have to double-backslash-escape the brackets and the period in order for them to be treated literally. Try this:
Code:
RS="\\[J\\.System Info\\]"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass a shell variable to an AWK command chogall Programming 1 12-23-2010 10:12 AM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
get variable out from awk sharathkv25 Programming 1 05-08-2007 06:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration