Sponsored Content
Top Forums Shell Programming and Scripting Issue executing grep command on Solaris Post 302974448 by Don Cragun on Monday 30th of May 2016 07:52:06 PM
Old 05-30-2016
There is an extraneous pipe symbol in your second Linux command line:
Code:
grep -m 1 '</name>' jdbc.xml| |sed 's/\(<name>\|<\/name>\)//g'| sed -e 's/^[ \t]*//'

that would generate a syntax error in shells on both Linux and on Solaris systems.

And, even if Solaris systems had a grep that supported the non-standard options provided as extension on Linux systems, you would also find that the sed commands you're using use extended regular expressions in the substitute commands (when the standards state that basic regular expressions are to be used there, and Solaris sed conforms to the standards and would generate bad BRE syntax errors). But by replacing both the one or two grep commands and both sed commands in your two pipelines with a single awk command as shown below:
Code:
printf "Solaris awk replacement for Linux pipeline:
	grep -A1 '<name>user</name>' jdbc.xml|
	grep -v '<name>user</name>'|
	sed 's/\(<value>\|<\/value>\)//g'|
	sed -e 's/^[ \t]*//'
"
/usr/xpg4/bin/awk '
c {	gsub("[[:space:]]|<[/]value>", "")
	print
	c = 0
}
/<name>user<\/name>/ {
	c = 1
	next
}' jdbc.xml

printf "\nSolaris awk replacement for Linux pipeline:
	rep -m 1 '</name>' jdbc.xml|
	sed 's/\(<name>\|<\/name>\)//g'|
	sed -e 's/^[ \t]*//' 
"
/usr/xpg4/bin/awk '
/<\/name>/ {
	gsub("[[:space:]]|<[/]*name>", "")
	print
	exit
}' jdbc.xml

we get code that would run more efficiently and faster on both Linux and Solaris systems.
 

10 More Discussions You Might Find Interesting

1. Solaris

Troubles building on solaris 9 and executing on solaris 10

Hi, I have to build an application on solaris 9 which is supposed to run on solaris 10 computers. I heard that solaris 9 builds should run on solaris 10 without any troubles. However, there is some trouble. Calling ldd on the programm reveals that "libgcc_s.so.1" and "libstdc++.so.6" are... (4 Replies)
Discussion started by: mikehammer80
4 Replies

2. Shell Programming and Scripting

issue with grep command

i am using 'psu' to grep the status of a process like below :- psu|grep -i agentf 29559 29552 0 00:53:05 ? 0:57 gn1avm_agent -n AGENTF1 28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1 29552 28946 0 00:53:05 ? 0:00 /bin/ksh... (6 Replies)
Discussion started by: deepakiniimt
6 Replies

3. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

4. UNIX for Dummies Questions & Answers

Grep command issue

How am I supposed to print with one Unix command the names (and only the names) of company JMT? Problems with scandinavian letters? By typing grep JMT url | egrep --only-matching ']+'I still have company name and + marks I should get rid of. I'd be very grateful of your help bacause I am new... (1 Reply)
Discussion started by: jht
1 Replies

5. Shell Programming and Scripting

CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is : -rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log -rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log -rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies

6. Shell Programming and Scripting

Issue while executing script

Hi, I'm trying to use the below command in a shell script, but couldn't. The command is working fine when I'm executing from the dollar prompt i.e. shell. Command: grep -i fail /home/applmgr/error.log |egrep -i "`date --date="-4 day" +"%m/%d/%Y"`|`date --date="-4 day" +"%m/%d/%y"`"... (8 Replies)
Discussion started by: venkatesh17
8 Replies

7. UNIX for Dummies Questions & Answers

grep issue (Solaris)

Can anyone explain this (i.e. why the 2nd grep does not find anything)?: -bash-3.00$ cat tmp.log sftp> chdir /home/test-dir sftp> mget thosefiles*.txt File "/home/test-dir/thosefiles*.txt" not found. -bash-3.00$ grep "s*.txt" tmp.log sftp> mget thosefiles*.txt File... (4 Replies)
Discussion started by: dhebden
4 Replies

8. Shell Programming and Scripting

Issue when executing shc command

Hi All, I am trying to create an executable using shc. I have a script which is creating 10 executables. The executables being created have the below issue. The message "Please contact your provider" is displayed even though I am not using the “-e” option. This message is coming for some... (5 Replies)
Discussion started by: temp_user
5 Replies

9. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

10. Shell Programming and Scripting

Issue with awk command between Linux and Solaris

Hi, Here is the output using bash profile on Linux uptime 04:59:14 up 16 days, 4:48, 2 users, load average: 1.00, 1.00, 1.20 Here is the output using bash profile on Solaris uptime 4:00am up 84 day(s), 22:21, 3 users, load average: 0.09, 0.10, 0.12 Now,... (4 Replies)
Discussion started by: mohtashims
4 Replies
largefile(5)                                            Standards, Environments, and Macros                                           largefile(5)

NAME
largefile - large file status of utilities DESCRIPTION
A large file is a regular file whose size is greater than or equal to 2 Gbyte ( 2**31 bytes). A small file is a regular file whose size is less than 2 Gbyte. Large file aware utilities A utility is called large file aware if it can process large files in the same manner as it does small files. A utility that is large file aware is able to handle large files as input and generate as output large files that are being processed. The exception is where additional files are used as system configuration files or support files that can augment the processing. For example, the file utility supports the -m option for an alternative "magic" file and the -f option for a support file that can contain a list of file names. It is unspecified whether a utility that is large file aware will accept configuration or support files that are large files. If a large file aware utility does not accept configuration or support files that are large files, it will cause no data loss or corruption upon encountering such files and will return an appropriate error. The following /usr/bin utilities are large file aware: adb awk bdiff cat chgrp chmod chown cksum cmp compress cp csh csplit cut dd dircmp du egrep fgrep file find ftp getconf grep gzip head join jsh ksh ln ls mdb mkdir mkfifo more mv nawk page paste pathchck pg rcp remsh rksh rm rmdir rsh sed sh sort split sum tail tar tee test touch tr uncompress uudecode uuencode wc zcat The following /usr/xpg4/bin utilities are large file aware: awk cp chgrp chown du egrep fgrep file grep ln ls more mv rm sed sh sort tail tr The following /usr/xpg6/bin utilities are large file aware: getconf ls tr The following /usr/sbin utilities are large file aware: install mkfile mknod mvdir swap See the USAGE section of the swap(1M) manual page for limitations of swap on block devices greater than 2 Gbyte on a 32-bit operating sys- tem. The following /usr/ucb utilities are large file aware: chown from ln ls sed sum touch The /usr/bin/cpio and /usr/bin/pax utilities are large file aware, but cannot archive a file whose size exceeds 8 Gbyte - 1 byte. The /usr/bin/truss utilities has been modified to read a dump file and display information relevant to large files, such as offsets. cachefs file systems The following /usr/bin utilities are large file aware for cachefs file systems: cachefspack cachefsstat The following /usr/sbin utilities are large file aware for cachefs file systems: cachefslog cachefswssize cfsadmin fsck mount umount nfs file systems The following utilities are large file aware for nfs file systems: /usr/lib/autofs/automountd /usr/sbin/mount /usr/lib/nfs/rquotad ufs file systems The following /usr/bin utility is large file aware for ufs file systems: df The following /usr/lib/nfs utility is large file aware for ufs file systems: rquotad The following /usr/xpg4/bin utility is large file aware for ufs file systems: df The following /usr/sbin utilities are large file aware for ufs file systems: clri dcopy edquota ff fsck fsdb fsirand fstyp labelit lockfs mkfs mount ncheck newfs quot quota quotacheck quotaoff quotaon repquota tunefs ufsdump ufsrestore umount Large file safe utilities A utility is called large file safe if it causes no data loss or corruption when it encounters a large file. A utility that is large file safe is unable to process properly a large file, but returns an appropriate error. The following /usr/bin utilities are large file safe: audioconvert audioplay audiorecord comm diff diff3 diffmk ed lp mail mailcompat mailstats mailx pack pcat red rmail sdiff unpack vi view The following /usr/xpg4/bin utilities are large file safe: ed vi view The following /usr/xpg6/bin utility is large file safe: ed The following /usr/sbin utilities are large file safe: lpfilter lpforms The following /usr/ucb utilities are large file safe: Mail lpr The following /usr/lib utility is large file safe: sendmail SEE ALSO
lf64(5), lfcompile(5), lfcompile64(5) SunOS 5.10 7 Nov 2003 largefile(5)
All times are GMT -4. The time now is 11:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy