awk to get string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to get string
# 1  
Old 06-22-2017
awk to get string

Hello Gurus,
I am facing one issue to get a portion of string from /etc/oraInst.loc
I ran the below command
Code:
cat /etc/oraInst.loc | grep VIS | cut -d "=" -f2

the result is as below :
Code:
/u01/oracle/VIS/oraInventory

But I want only upto /u01/oracle/VIS.

How to achieve this.

Please advice.

Thanks-
P


Moderator's Comments:
Mod Comment Please use CODE tags correctly as required by forum rules!

Last edited by RudiC; 06-22-2017 at 06:39 PM.. Reason: Changed CODE tags.
# 2  
Old 06-22-2017
Hi pokhraj_d,

Obviously
Code:
cat /etc/oraInst.loc | grep VIS | cut -d "=" -f2 | sed 's#/oraInventory##'

would work but if you need a more generic answer, you need to provide the content of /etc/oraInst.loc.

Regards
Santiago
# 3  
Old 06-22-2017
Try
Code:
awk -F= '/VIS/ {n=split ($2, T, "/"); sub ("/" T[n] "$", "", $2); print $2}' /etc/oraInst.loc
/u01/oracle/VIS


Last edited by RudiC; 06-23-2017 at 02:55 AM.. Reason: Added field separator.
# 4  
Old 06-23-2017
Try:
Code:
while IFS== read key val rest
do
  case $val in
    (*VIS*) echo "${val%/*}"
  esac
done < /etc/oraInst.loc

# 5  
Old 06-23-2017
sed version:
Code:
sed -n 's#^.*=\(.*VIS\).*$#\1#p' /etc/oraInst.loc

Andrew
# 6  
Old 06-23-2017
Hello Gurus,
Thank you very much... It worked..

Thanks-
P
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

3. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

4. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

5. Shell Programming and Scripting

awk string comparison unterminated quoted string andrule of thumb

I have the logic below to look up for matches within the columns between the two files with awk. In the if statement is where the string comparison is attempted with == The issue seems to be with the operands, as 1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies

6. UNIX for Dummies Questions & Answers

awk for string between > and /n

Hi, I have a file that looks something like the following: >IGHV4-4*02 caggtgcagctgcaggagtcgggcccaggactggtgaagccttcggggaccctgtcc ctcacctgcgctgtctctggtggctccatcagcagtagtaactggtggagt tgggtccgccagcccccagggaaggggctggagtggattggggaaatctatcatagt gggagcaccaactacaacccgtccctcaagagtcgagtcaccatatcagta... (3 Replies)
Discussion started by: jyu429
3 Replies

7. Shell Programming and Scripting

awk : match the string and string with the quotes :

Hi all, Here is the data file: - want to match only lan3 in the output . - not lan3:1 file : OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE=""... (2 Replies)
Discussion started by: rveri
2 Replies

8. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

9. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

10. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies
Login or Register to Ask a Question