LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2011, 12:37 PM   #16
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976

Quote:
Originally Posted by manish72 View Post
I cannot use nawk or gawk as it is not availbale.Is there any work around for this?
Ok. You might try to replace the backslash with something else, then change it again before printing. Example:
Code:
NR == FNR {
  gsub(/input./,"")
  split($0,a," = ")
  b[a[1]]=a[2]
  next
}

{
  gsub(/@/,"")
  for (i in b) {
    #
    #  This should replace any single \ to ESC
    #
    gsub(/\\/,"\033",b[i])
    gsub(i,b[i])
  }
}

{
  #
  #  This should give the original \ back.
  #
  gsub("\033","\\")
  print
}
I'm not sure if AIX awk accepts the \NNN escape sequences, but the GNU awk guide does not mention compatibility issues (except for \xhh...). I chose a control-character to avoid unwanted substitutions of valid characters.
 
Old 07-12-2011, 12:40 PM   #17
manish72
LQ Newbie
 
Registered: Mar 2011
Posts: 11

Original Poster
Rep: Reputation: 0
I have edited the required op.The slashes after the @xcom.range.remote_file_system @:need to be double(\\). The ones before @xcom.range.remote_file_system @: need to remain as 4 (\\\\). In short, I my required op is exactly what grail has got by using latest gawk. sadly , I cannot use it. Would be very helpful if someone could suggest another way of doing this operation witout awk? Or provide a workaround for this awk statement. Thanks in advance!
 
Old 07-12-2011, 12:44 PM   #18
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by manish72 View Post
I have edited the required op.
Please don't do that! Think at other users/learners trying to follow the discussion: answers are related to the first version of the Original Post. Now they do not make sense anymore and the discussion is very hard to follow.
 
Old 07-12-2011, 12:46 PM   #19
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by manish72 View Post
I have edited the required op.The slashes after the @xcom.range.remote_file_system @:need to be double(\\).
If you want to try my code above, now you have to change the last gsub statement from
Code:
  gsub("\033","\\")
to
Code:
  gsub("\033\033","\\")
 
Old 07-12-2011, 12:58 PM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
So can I confirm that your original awk was converting 4 slashes to 1 and not 2 to 1 and 4 to 2?
If it is doing the latter, you could simply put in twice as many slashes so that when halved, as awk does in string notation (ie "\\" is printed as \),you
would have the correct number. Just add:
Code:
gsub(/\\/,"&\\")
 
Old 07-18-2011, 03:52 AM   #21
manish72
LQ Newbie
 
Registered: Mar 2011
Posts: 11

Original Poster
Rep: Reputation: 0
Thank you all for your response. I used grail's suggestion. I doubled my slashes in the awk op using sed. Now i have the op in corrcet format.
 
Old 07-18-2011, 10:28 AM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
I doubled my slashes in the awk op using sed.
Glad you settled on a solution but would seem odd to use both??
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
output formatting with awk. pinga123 Programming 4 11-26-2010 08:56 AM
date formatting from stat command tensigh Programming 10 08-30-2010 05:13 AM
Using awk/sed to convert linefeed to csv, with some formatting jaykup Programming 1 04-03-2009 06:18 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
sed or other formatting command help SeT Linux - General 1 10-13-2004 07:57 PM


All times are GMT -5. The time now is 06:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration