Pattern manipulation in korn shell script using sed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern manipulation in korn shell script using sed.
# 1  
Old 08-22-2008
Pattern manipulation in korn shell script using sed.

Hi,

Could any one let me know, how can I cut the last field in below mentioned line.

net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.37.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.1.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.38.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.2.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.39.0,10.253.0.1
net,-hopcount,0,,0,10.14.185.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,0,10.14.185.1
net,-hopcount,0,-netmask,255.255.0.0,,,,,10.253.0.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.9.0,10.253.0.1
net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.36.0,10.253.0.1

I want to get all the gate way mentioned in bold above., ie last 10.253.0.1. we can't use the filed separator as " , " while using awk as the number of parameter varies. Tried all awk but hope can do it using sed. would like to know the format.

Thanks,
Ajilesh
# 2  
Old 08-22-2008
With awk you can get the last field with $NF:

Code:
awk -F, '{print $NF}' file

Regards
# 3  
Old 08-22-2008
Try this..

$ awk -F"," '{ print $NF }' <<File name >>
# 4  
Old 08-22-2008
It works...!! Great..!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text manipulation with sed/awk in a bash script

Guys, I have a variable in a script that I want to transform to into something else Im hoping you guys can help. It doesn't have to use sed/awk but I figured these would be the simplest. DATE=20160120 I'd like to transform $DATE into "01-20-16" and move it into a new variable called... (8 Replies)
Discussion started by: dendenyc
8 Replies

2. Shell Programming and Scripting

Korn Shell regular pattern

Hello, I can't seem to understand korn shell regular expression. I am trying to extract the tagfrom its own filename string. var="LNX_1.2.0.0.af329a3da.tar" whereby af329a3da is the tagI am trying to extract out from. I am trying to avoid using IFS because future modifications... (5 Replies)
Discussion started by: howhan
5 Replies

3. Shell Programming and Scripting

Korn Shell for pattern matching and extracting

Guys, i'm new to shell scripting. Here's what i need. I need a shell script which would read a file containing only 1 line which never changes. File containts - SQL_Mgd_Svc_ELONMCL54496 |EMEA\brookkev, EMEA\fieldgra, EMEA\tidmamar, EMEA\attfiste, EMEA\baldogar, EMEA\clarkia2, EMEA\conwasha,... (9 Replies)
Discussion started by: butterfly20
9 Replies

4. Shell Programming and Scripting

sed string manipulation in shell script

Hello, I have 1000 of sql queries and i need to push column value in query. e.g. SET INSERT_ID=1 INSERT INTO test (id,name) VALUES ('a'); SET INSERT_ID=2 INSERT INTO test (id,name) VALUES ('b'); SET INSERT_ID=3 INSERT INTO test (id,name) VALUES ('c'); SET INSERT_ID=4 INSERT INTO test... (12 Replies)
Discussion started by: mirfan
12 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. Shell Programming and Scripting

AIX Korn shell sed -s problem

In a Korn shell script I have, cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt The header is short {{Company flag1}} But the result in header.txt is {{Company $cnumb}} The value of $cnumb is 120. I am trying to get the value of $cnumb into the header. I have tried /'$cnumb'/g,... (10 Replies)
Discussion started by: jcarrott
10 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question