Sponsored Content
Top Forums Shell Programming and Scripting grep middle word between two patterns Post 302393393 by steadyonabix on Monday 8th of February 2010 06:35:42 PM
Old 02-08-2010
Code:
#! /bin/ksh

INPUT="(DB_NAME), (163.24 25), (16/02/10 23:40), (COMPLETED), "

echo $INPUT | nawk -F",|, " ' {
        for( i = 65; i <= 68; i++ )
                printf("\"%c\"%s\n", i,"="$(i - 64))
        }' | tr "()" "'"

Output: -

Code:
"A"='DB_NAME'
"B"='163.24 25'
"C"='16/02/10 23:40'
"D"='COMPLETED'



---------- Post updated at 11:35 PM ---------- Previous update was at 08:37 PM ----------

Actually the delimiter is the , not ().

If you want to do the assignement to the variables form the script you could try this: -

Code:
#! /bin/ksh
 
INPUT="(DB_NAME), (163.24 25), (16/02/10 23:40), (COMPLETED), "
 
echo $INPUT | nawk -F",|, " ' {
        for( i = 65; i <= 68; i++ )
                printf("export %c%s\n", i,"="$(i - 64))
        }' | tr "()" "'" > tmp_file
 
. tmp_file 2>/dev/null || echo "Error in export file"
 
echo "A=$A"
echo "B=$B"
echo "C=$C"
echo "D=$D"
 
rm -f tmp_file

Output: -

Code:
A=DB_NAME
B=163.24 25
C=16/02/10 23:40
D=COMPLETED

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep multiple patterns + the whole word only

Guys, i used egrep "pattern1|pattern2". But the whole word is searched. But i want the output if only the exact word is matched. i.e the output is got evenif a part of the pattern is matched. I tried the -w opion but its showing usage error. Please help me out on this one. please sent me... (2 Replies)
Discussion started by: meheretoknow
2 Replies

2. Shell Programming and Scripting

Grep with wildcard in middle of word

How can grep G.*schema give me the result: ${Gacntg_dt}""'"' doesn't G.*schema say give me an unlimited number of characters between G and schema? :confused: (3 Replies)
Discussion started by: danmauer
3 Replies

3. Shell Programming and Scripting

add a word in the middle

I have a file where in I need to add gctunit1/gtdivcompebb1/ after the = sign for example: gtfix31/gctunit_gtdivcompebb1/csclkswcompbypassstepgnnnh = gctunit1/gtdivcompebb1/csclkswcompbypassstepgnnnh (3 Replies)
Discussion started by: pitagi
3 Replies

4. UNIX for Dummies Questions & Answers

Is it possible to grep with a newline in the middle of an expression?

I'm hoping that there is a way to do this. I'm sure I won't be able to get the answer I need on the deadline I need it...but at least I'll learn how to solve this problem. I have a file that looks like this: (00:14:25\$ head -27 QNHDSPACEDVR Name: PollDhctAVFSInfo 00:0F:21:4B:00:6A Name:... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

5. UNIX for Dummies Questions & Answers

printing only the middle word between two patterns

How would I print the word "and" between the words "FOO" and BAR" using sed? My file has three words in it FOO and BAR. I only want the word "and". Thanks every one. (7 Replies)
Discussion started by: tigta09
7 Replies

6. Shell Programming and Scripting

Find zipcode with Grep with optional space in middle

Hello everyone. I am new to unix, nice to meet you all. I have a small problem with a question. I have to write a command that finds all the postal codes in a txt file. All postal codes will begin on its own line in the txt file. This is the formal of postal code: "A#A#A#" or "A#A #A#" A... (3 Replies)
Discussion started by: leonmerc
3 Replies

7. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

8. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

9. Shell Programming and Scripting

Grep patterns

Hi Experts, I have a log file like this.I need to filter the Index name and elapsed time(only created ). 06:36:39 SQL> create index XYZ_F75 on XYZ 06:36:39 2 ("GRP_ID", "_ID") parallel 64 nologging 06:36:39 3 tablespace XARGS_IDX 06:36:39 4 ; Index created. Elapsed:... (2 Replies)
Discussion started by: navsan420
2 Replies

10. Shell Programming and Scripting

Help needed in excluding certain word patterns

Hi, I need help with following. I need to exclude words that match following patterns a. more than length 4 (example SBRAP) b. contains mixture uppercase and lower case regardless of the length (example GSpD) File contains COFpC MCHX SP SNFCA GEH SBRAP DGICA JPMpE WFCpP GSpD AXL... (5 Replies)
Discussion started by: jakSun8
5 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/ksh93 /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/ksh93 /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/sfw/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. NOTES
Restricted shells should not be listed in /etc/shells. SunOS 5.11 1 Nov 2007 getusershell(3C)
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy