Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to grep the word and display only the second word from it Post 302263334 by joeyg on Monday 1st of December 2008 10:30:01 AM
Old 12-01-2008
Hammer & Screwdriver Here is another approach

Code:
> cat file85
'Y',getdate(),'N','V',NULL .....
'N',getdate(),'Y','D',NULL .....
'Y','N','Y',getdate(),'Y','D',NULL ....
> cat file85 | sed "s/getdate()/~&1/" | tr "~" "\n" | grep "getdate()" | cut -d"," -f3
'V'
'D'
'D'

[Note: this was done purposefully LONG to help show how the commands all worked together.]
Explained
cat the file
sed to put a ~ before any instance of getdate()
tr the ~ to a new-line; forcing onto own line
grep for the getdate() to select only those lines
cut -d"," -f3 to set delimiter to , and output the third field
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep a word and display its column

Hi, I need idea about this, say I have this line: 05 21 * * 0,6 /user/clean.desktop.sh > /tmp/desktop_rpt 2>&1 I would need to grep the word desktop and display the /user/clean.desktop.sh and not the whole line. And if I have some more lines say, 05 21 * * 0,6 /user/clean.desktop.sh >... (1 Reply)
Discussion started by: Orbix
1 Replies

2. UNIX for Dummies Questions & Answers

how to grep for a word and display only the word

Hi, When we "grep" for a word in a file, it returns the lines containing the word that we searched for. Is there a way to display only the words and not the entire line containing them. Thanks Ananth (6 Replies)
Discussion started by: ananthmm
6 Replies

3. Shell Programming and Scripting

How to Grep for particular word and display..

Hi Guru's.... I've one log file in all my systems which writes the backup information.. I'have written a command like this: ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' We have nearly 50 systems in our... (2 Replies)
Discussion started by: suri.tyson
2 Replies

4. Shell Programming and Scripting

grep display word only

Folks, is it possible to display only words with grep (or any built-in ultility)? I have more than 1 pattern to search, say apple & orange The text goes like this: So I need to display all the words starting with apple or orange The output should be: Any idea? (7 Replies)
Discussion started by: bsddaemon
7 Replies

5. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. Shell Programming and Scripting

Grep word after last occurance of string and display next few lines

Hi, I wanted to grep string "ERROR" and "WORNING" after last occurrence of String "Starting" only and wanted to display two lines after searched ERROR and WORNING string and one line before. I have following cronjob log file "errorlog" file and I have written the code for same in Unix as below... (17 Replies)
Discussion started by: nes
17 Replies

9. Shell Programming and Scripting

Grep for a word or word with underscore

I have a file "test" with following contents: cat test abc abcd_efg abc_abc I want to only grep for abc or abc_ without getting other results, how do I achieve this? If I use grep -w abc test option I get only abc and not abc_. If I use egrep "abc|abc_" test its still printing... (3 Replies)
Discussion started by: ctrld
3 Replies

10. Shell Programming and Scripting

How to grep for a word and display last transection?

Hi, When we "grep" for a word in a file, it returns the last lines containing the word that we searched for. Is there a way to display last line to grep. Thanks Ex log. Ex. logname.log 2015-07-29 06:43:07.023|BETA |2015-07-29... (5 Replies)
Discussion started by: ooilinlove
5 Replies
GETDATE(3)						     Linux Programmer's Manual							GETDATE(3)

NAME
getdate() - convert a string to struct tm SYNOPSIS
#define _XOPEN_SOURCE #define _XOPEN_SOURCE_EXTENDED #include <time.h> struct tm *getdate (const char *string); extern int getdate_err; #define _GNU_SOURCE #include <time.h> int getdate_r (const char *string, struct tm *res); DESCRIPTION
The function getdate() converts a string pointed to by string into the tm structure that it returns. This tm structure may be found in static storage, so that it will be overwritten by the next call. In contrast to strptime(3), (which has a format argument), getdate() uses the formats found in the file of which the full path name is given in the environment variable DATEMSK. The first line in the file that matches the given input string is used for the conversion. The matching is done case insensitively. Superfluous whitespace, either in the pattern or in the string to be converted, is ignored. The conversion specifications that a pattern can contain are those given for strptime(3). One more conversion specification is accepted: %Z Timezone name. When %Z is given, the value to be returned is initialised to the broken-down time corresponding to the current time in the given time zone. Otherwise, it is initialised to the broken-down time corresponding to the current local time. When only the weekday is given, the day is taken to be the first such day on or after today. When only the month is given (and no year), the month is taken to be the first such month equal to or after the current month. If no day is given, it is the first day of the month. When no hour, minute and second are given, the current hour, minute and second are taken. If no date is given, but we know the hour, then that hour is taken to be the first such hour equal to or after the current hour. RETURN VALUE
When successful, this function returns a pointer to a struct tm. Otherwise, it returns NULL and sets the global variable getdate_err. Changes to errno are unspecified. The following values for getdate_err are defined: 1 The DATEMSK environment variable is null or undefined. 2 The template file cannot be opened for reading. 3 Failed to get file status information. 4 The template file is not a regular file. 5 An error is encountered while reading the template file. 6 Memory allocation failed (not enough memory available). 7 There is no line in the file that matches the input. 8 Invalid input specification. NOTES
Since getdate() is not reentrant because of the use of getdate_err and the static buffer to return the result in, glibc provides a thread- safe variant. The functionality is the same. The result is returned in the buffer pointed to by res and in case of an error the return value is nonzero with the same values as given above for getdate_err. The POSIX 1003.1-2001 specification for strptime() contains conversion specifications using the %E or %O modifier, while such specifica- tions are not given for getdate(). The glibc implementation implements getdate() using strptime() so that automatically precisely the same conversions are supported by both. The glibc implementation does not support the %Z conversion specification. ENVIRONMENT
DATEMSK File containing format patterns. TZ, LC_TIME Variables used by strptime(). CONFORMING TO
ISO 9899, POSIX 1003.1-2001 SEE ALSO
localtime(3), strftime(3), strptime(3), time(3) 2001-12-26 GETDATE(3)
All times are GMT -4. The time now is 06:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy