LinuxQuestions.org
Help answer threads with 0 replies.
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 02-03-2011, 09:50 PM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,505

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890

Quote:
does Solaris's awk or nawk allow multiple field delimiters? I don't have nawk at hand to check.
Doing better than me ... I don't have Solaris to check
 
Old 02-04-2011, 02:15 AM   #17
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by crts View Post
Here's another sed:
Code:
sed -nr '4,$ {s/\[([^,]+).*$/\1 /;H};$ {g;s/\n//gp}' blackout_txt
Awesome! This is the solution I was looking for, yesterday... before I went to sleep! Thanks, crts!
 
Old 02-04-2011, 08:10 AM   #18
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,614

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Quote:
Originally Posted by kurumi View Post
from memory, don't think Solaris's sed has the -r option. i may be wrong
Don't know either since I don't have solaris. In any case
Code:
sed -n '4,$ {s/\[\([^,]*\).*$/\1 /;H};$ {g;s/\n//gp}' blackout_txt
should also work.
@OP: Try the 'sed' in post #11 first since the escaping is a strain on the eyes.
 
Old 02-04-2011, 10:05 AM   #19
z1p
Member
 
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
Quote:
Originally Posted by kurumi View Post
does Solaris's awk or nawk allow multiple field delimiters? I don't have nawk at hand to check.
The awk i have on Solaris 9 using tcsh does support multiple field delimiters. What is odd is that the man page shows that it does support it, only nawk does. But in practice it accepts specifying multiple delimiters. However, the awk presented does yield the results the OP is looking for. So far I can't find a single command that will work for Solaris/tcsh. Its looking like piping multiple command together is required.


Here is what I get

Code:
43> sed -n '4,$ {s/\[\([^,]*\).*$/\1 /;H};$ {g;s/\n//gp}' blackout_txt
sed: command garbled: 4,$ {s/\[\([^,]*\).*$/\1 /;H};$ {g;s/\n//gp}

46> awk -F"[][,]" 'NR > 3{printf $2" "}END{print ""}' blackout_txt
LISTENER_ORA_ORCLSTG_orclstg, oracle_listener] orclstg, host] orclstg, oracle_database]

47> sed -nr '4,$ {s/\[([^,]+).*$/\1 /;H};$ {g;s/\n//gp}' blackout_txt
sed: illegal option -- r

48> sed -e '1,3d' -e's/.\(.*\)/\1/' -e 's/\(.*\)./\1/' blackout_txt | awk -F, '{ORS=" "} {print $1} END {print "\n"} '
LISTENER_ORA_ORCLSTG_orclstg orclstg orclstg

50> awk 'NR > 3 { sub(/^./,"",$1); sub (/.$/,"",$1); printf "%s ", $1 } END { printf "\n" }' blackout.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
My attempts to use sed to strip out the newline always ends up with not being able to strip out the extra info from the lines.
 
Old 02-04-2011, 10:28 AM   #20
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,614

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
Quote:
Originally Posted by z1p View Post
Here is what I get

Code:
43> sed -n '4,$ {s/\[\([^,]*\).*$/\1 /;H};$ {g;s/\n//gp}' blackout_txt
sed: command garbled: 4,$ {s/\[\([^,]*\).*$/\1 /;H};$ {g;s/\n//gp}
Well, that is not very descriptive. And since I do not have Solaris I can't really debug it. Both work fine with Linux/Bash.
 
Old 02-04-2011, 10:30 AM   #21
z1p
Member
 
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
Ok I found a single awk command to do it. It depends on the format of the lines, but works on my Solaris system.

Code:
66> awk 'NR > 3 { A=substr($1,2,length($1)-2); printf "%s ", A } END { printf "\n" }' blackout_txt
LISTENER_ORA_ORCLSTG_orclstg orclstg orclstg
67>

Just found that the awk command in post #2 and post #8 work if nawk is used instead of awk on my Solaris system.

Last edited by z1p; 02-04-2011 at 10:39 AM.
 
Old 02-05-2011, 02:01 AM   #22
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,505

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
I am curious if maybe (n)awk on Solaris might not accept the switch (-F) to take multiple delimiters that maybe FS would.
Can we try:
Code:
awk 'BEGIN{FS="[][,]"}NR > 3{printf $2" "}END{print ""}' file
 
Old 02-06-2011, 12:23 PM   #23
z1p
Member
 
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
Quote:
Originally Posted by crts View Post
Well, that is not very descriptive. And since I do not have Solaris I can't really debug it. Both work fine with Linux/Bash.
Sorry about that, but that is all Solaris gave me.
 
Old 02-15-2011, 09:55 PM   #24
pavan27
LQ Newbie
 
Registered: Nov 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Experts,

Bunch of Thanks for helping me. I got a very good help, and in timely fashion.

Thank you so much. i was able to complete my task.
 
  


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
sed command help tekmann33 Linux - Newbie 1 10-20-2008 04:06 PM
sed command help prashant.kumar Linux - General 6 10-15-2007 05:48 PM
sed command ancys Programming 2 08-05-2006 10:50 AM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM
sed command kwigibo Linux - General 3 04-21-2002 04:11 PM


All times are GMT -5. The time now is 12:38 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