Parsing the list in korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing the list in korn shell
# 1  
Old 10-19-2010
Parsing the list in korn shell

Hi

I wanted to print/store just a specific element of the list . I have got the list as an output of grep command.

here is code snap below :

Code:
end_no=`egrep -ni '!return code: 0|return code other than 0' temp.log | cut -d':' -f1`

this will return the line numbers in end_no. I just wanted to know the 2nd positioned line numbers. please let me know the way to do .
Thanks:

Moderator's Comments:
Mod Comment Use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 10-19-2010 at 07:11 AM..
# 2  
Old 10-19-2010
Use an array:
Code:
#!/usr/bin/ksh

set -A end_no

end_no="`egrep -ni '!return code: 0|return code other than 0' temp.log | cut -d':' -f1`"

echo ${end_no[2]}

exit 0

Not sure how the value/list of end_no looks alike but generally that should work.
# 3  
Old 10-19-2010
Thats is not working .. no output from echo stmt.

the list looks like this - 22 44 66:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

List of 'if -f' options - AIX / Korn Shell

Hi all, Can someone point me in the right direction for a manual on the various statement options for 'if'. Basically I have a piece of code which says: if ] and I wondered what the -f was. I know the '!' means not equal.. As usual any help much appreciated.. (5 Replies)
Discussion started by: Grueben
5 Replies

2. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

3. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

4. Shell Programming and Scripting

String parsing in Korn Shell

Hi everybody, I have a string stored in a variable called record: record="SNMPv2-SMI::ent.9.9.43.1.3.9.2 = Timeticks: (177330898) 20 days, 12:35:08.98" I want to write some regular expressions good for Korn Shell to extract the number between parenthesis, in this case 177330898, and put it in... (3 Replies)
Discussion started by: omoyne
3 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. Shell Programming and Scripting

Parsing in korn shell

Hi Everyone, how do i parse following string from a file xyz.log in korn shell ? aa/bb{ CT{ GG{jjj/test} Thanks in advance, sweta (1 Reply)
Discussion started by: swetarati
1 Replies

7. Shell Programming and Scripting

Korn pattern-list with a variable

I am trying to use a pattern-list match in korn shell using a variable and it always seems to regard the pattern-list as a literal: Using the directory names explicitly in the pattern-list works fine: ls @(test|test1)/test.txt and returns: test/test.txt Trying to use a variable for this... (2 Replies)
Discussion started by: partchimp
2 Replies

8. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

9. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. Shell Programming and Scripting

korn shell + sftp + list files

Hello!!! I need a korn shell script in AIX that inside sftp environment, changes a remote directory, lists the files inside it, and stores in an array. I got it working before make a sftp, but after.. I can't.. The way it is, it lists the files in local path... so.. not what I want, but... (1 Reply)
Discussion started by: alienET
1 Replies
Login or Register to Ask a Question