![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| option followed by : taking next option if argument missing with getopts | gurukottur | Shell Programming and Scripting | 2 | 03-17-2008 12:46 PM |
| -n option | ravi raj kumar | Shell Programming and Scripting | 1 | 01-03-2008 09:20 AM |
| what is gcc -e option in C | useless79 | High Level Programming | 3 | 12-05-2007 01:36 PM |
| su option | lesstjm | UNIX for Advanced & Expert Users | 1 | 11-02-2005 01:54 PM |
| cut -f option | 435 Gavea | UNIX for Dummies Questions & Answers | 1 | 11-10-2003 05:50 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
bad option(s) with awk
Hi All
I am trying to split a string which is like below -p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17 i want to split "_" as delimiter. Please find the code below Code:
#!/bin/ksh
cd /usr/home/dfusr/backup
OriginalString='-p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17'
myCmdLineArg1=""
myCmdLineArg2=""
set -A cmdLineArgs `echo "$OriginalString"| awk '{z=split($0,flds,"_")
for(i=1;i<=z;i++)
print flds[i]}'`
echo "cmdLineArgs[0]:::::::: ${cmdLineArgs[0]}"
echo "cmdLineArgs[1]:::::::: ${cmdLineArgs[1]}"
myCmdLineArg1=${cmdLineArgs[0]}
myCmdLineArg2=${cmdLineArgs[1]}
Please advice where i am doing wrong in above code. Does awk works with "-" at first place. Please correct my code. Thanks- Raj Last edited by radoulov; 2 Weeks Ago at 08:55 AM.. Reason: Use code tags, please! |
|
|||||
|
You can also do :
Code:
#!/bin/ksh -x
OriginalString='-p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17'
oldIFS="$IFS" ; IFS=
set -A cmdLineArgs -- $OriginalString
IFS="$oIFS"
echo "cmdLineArgs[0]:::::::: ${cmdLineArgs[0]}"
echo "cmdLineArgs[1]:::::::: ${cmdLineArgs[1]}"
Code:
IFS=_ set -A cmdLineArgs -- $OriginalString Jean-Pierre |
|
|||||
|
Quote:
I think you mean: Code:
IFS=_ Code:
IFS= Quote:
You cannot set IFS only for the set builtin using that syntax. You could write something like this: Code:
zsh-4.3.10[t]% cat s
#!/bin/ksh
OriginalString='-p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17'
IFS=_ ; set -A cmdLineArgs -- $OriginalString
echo "cmdLineArgs[0]:::::::: ${cmdLineArgs[0]}"
echo "cmdLineArgs[1]:::::::: ${cmdLineArgs[1]}"
zsh-4.3.10[t]% ./s
cmdLineArgs[0]:::::::: -p/usr/home/dfusr/adm/props/Comments.properties
cmdLineArgs[1]:::::::: -iPEL17
---------- Post updated at 03:29 PM ---------- Previous update was at 03:21 PM ---------- Or you can use zsh ![]() Code:
zsh-4.3.10[t]% s=-p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17
zsh-4.3.10[t]% print -- ${${(s:_:)s}[1]}
-p/usr/home/dfusr/adm/props/Comments.properties
zsh-4.3.10[t]% print -- ${${(s:_:)s}[2]}
-iPEL17
|
|
|||||
|
Quote:
Code:
> OriginalString='-p/usr/home/dfusr/adm/props/Comments.properties_-iPEL17'
> set -x
> IFS=_ set -A cmdLineArgs -- $OriginalString
+ IFS=_
+ set -A cmdLineArgs -- -p/usr/home/dfusr/adm/props/Comments.properties -iPEL17
> echo "cmdLineArgs[0]:::::::: ${cmdLineArgs[0]}"
+ echo cmdLineArgs[0]:::::::: -p/usr/home/dfusr/adm/props/Comments.properties
cmdLineArgs[0]:::::::: -p/usr/home/dfusr/adm/props/Comments.properties
> echo "cmdLineArgs[1]:::::::: ${cmdLineArgs[1]}"
+ echo cmdLineArgs[1]:::::::: -iPEL17
cmdLineArgs[1]:::::::: -iPEL17
>
|
|
||||
|
Thank You Its Working.
One more question. I am reading data from the database and writing to temporary file in the below format. 1=XP|external_component|com.adp.meetingalertemail.processing.MeetingAlertEmail|EMAILALERTPUSH|32|4#XP |classpath|/usr/home/dfusr/lib/xalan.jar: /usr/home/dfusr/lib/xerces.jar: /usr/home/dfusr/lib/xml.jar: /usr/home/dfusr/lib/classes12.zip The data is writing in multiple rows as i want to write the same in one row for the same sequnce number. 1 in the above example Find below the code i am retrieving from the database and writing to myJobTaskAttribListFile. sqlplus -s $DBCredentials 1> $myJobTaskAttribListFile <<-EndOFSQL SET DEFINE OFF; SET SERVEROUT ON SET LINESIZE 3400; DECLARE i_job_id NUMBER := $myJobId ; o_run_status_id NUMBER := 0 ; i_end_time VARCHAR2(1000) ; i_total_errors NUMBER := 0 ; i_total_warnings VARCHAR2(1000) ; i_total_inserted NUMBER := 0 ; i_total_updated NUMBER := 0 ; i_total_rejected NUMBER := 0 ; i_log_file VARCHAR2(1000) ; i_job_run_message VARCHAR2(512) ; i_modlast_by VARCHAR2(1000) ; o_sqlcode NUMBER := 0 ; o_sqlmsg VARCHAR2(1000) ; BEGIN $myUSPLoadJobTaskAttribs ( i_job_id, o_run_status_id, o_sqlcode, o_sqlmsg ); END; / EndOFSQL Please advice how can i write the same in one row for each sequnce number. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|