matching first instance of FS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching first instance of FS
# 1  
Old 04-22-2008
matching first instance of FS

Hi All,

I have a property in a file as:
property=value=a


If I use FS="=" then I want only first = to be considered as field separator and remaining as value
Code:
echo -e "property=value=a" | awk -F= '{print $2}'

ie my $2 should be value=a

Can anyone please help me with this. I need it in awk

Thanks in Advance
Guru

Last edited by Yogesh Sawant; 04-22-2008 at 04:28 AM.. Reason: added code tags
# 2  
Old 04-22-2008
Code:
echo  "property=value=a" | awk -F= '{print $2"="$3}'

or
Code:
echo  "property=value=a" | awk 'BEGIN{FS=OFS="="}{print $2, $3}'

Regards
# 3  
Old 04-22-2008
Thanks for your reply franklin..

I am reading the properties from a file:

so there can be other files with

property=value

in this case I can't print using OFS="=" as there is no 3rd field

How to do in that case
# 4  
Old 04-22-2008
Quote:
Originally Posted by gurukottur
Thanks for your reply franklin..

I am reading the properties from a file:

so there can be other files with

property=value

in this case I can't print using OFS="=" as there is no 3rd field

How to do in that case
In that case:

Code:
awk 'BEGIN{FS=OFS="="}{print $(NF-1), $(NF)}'

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

3. UNIX for Advanced & Expert Users

Grep the only instance name

Hi, I want to get the only application name from the server. Ex: if i give $ ps -ef | grep bw. It will show all BW process with entire path. It will little confuse to list out the process. Can anyone have syntax to get only the instance name. I need this for be, hawk,ems also. Please... (2 Replies)
Discussion started by: ckchelladurai
2 Replies

4. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

5. Shell Programming and Scripting

sed/awk: Delete matching words leaving only the first instance

I have an input text that looks like this (comes already sorted): on Caturday 22 at 10:15, some event on Caturday 22 at 10:15, some other event on Caturday 22 at 21:30, even more events on Funday 23 at 11:00, yet another event I need to delete all the matching words between the lines, from... (2 Replies)
Discussion started by: GrinningArmor
2 Replies

6. Shell Programming and Scripting

Keep the last instance of the record

Hi All, I have a input file like 1| abc 1| abcd 1| abcde 2| abc 2| abcd 3| abcde I want the output like 1| abcde 2| abcde Any help would be highly appreciated. Thanks in advance. (9 Replies)
Discussion started by: lrkp
9 Replies

7. Shell Programming and Scripting

What does : do in this instance

Guys please see below functions to return a status depending on user input. Both seem to work the same. The second way has a : line which i can't understand or see in a ksh manual anywhere. Instead of doing the variable change if its empty on this line the first function simply does it on the... (7 Replies)
Discussion started by: lavascript
7 Replies

8. Shell Programming and Scripting

Sed on first instance only

Hi, I've been trying to figure this one out and found a post about this on the forum here but the solution didn't seem to work for me. Basically what I have is a file that looks something like: stuff morestuff 0 otherthing 0 etc I want to substitute for the 0 but what I want to... (9 Replies)
Discussion started by: eltinator
9 Replies

9. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

10. Linux

OTRS instance

hi frnds here i m trying to configure OTRS instance but i m getting the following error message while runnning through browser. I m writing the following http://192.168.1.55:8080/otrs2/index.pl " #!/usr/bin/perl -w... (7 Replies)
Discussion started by: naik_mit
7 Replies
Login or Register to Ask a Question