Sponsored Content
Full Discussion: Problem with Grep command
Top Forums Shell Programming and Scripting Problem with Grep command Post 302715981 by durden_tyler on Monday 15th of October 2012 10:20:00 PM
Old 10-15-2012
Using a shell script:

Code:
$
$ cat f10
FWKD|FWKD_DEV|1
FWKD1|FWKD_QA|2
$
$ cat f10.sh
#!/usr/bin/ksh
sn=$1
IFS="|"
while read db sch srv
do
  if [ "$srv" == "$sn" ]
  then
    echo "$db|$sch|$srv"
    exit
  fi
done < f10

$
$
$ ./f10.sh 1
FWKD|FWKD_DEV|1
$
$

Using awk or Perl would be shorter and easier -

Code:
$
$
$ awk -F"|" -v sn="2" '$3 == sn' f10
FWKD1|FWKD_QA|2
$
$
$ perl -F"\|" -slane 'print if $F[2] == $sn' -- -sn=2 f10
FWKD1|FWKD_QA|2
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep Problem

I have a large file that I am grepping to find a certain string. grep 'C:\Data\Directory\Test.txt' test.txt It can not find it even though I know it is in there . I know that there is a problem with the backslashes but I can't get it to work. I tried grep... (2 Replies)
Discussion started by: lesstjm
2 Replies

2. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies

3. Solaris

Grep problem

Hi all, I get this this error message grep: illegal option -- q Usage: grep -hblcnsvim pattern file when I execute this command rsh <host ip> " ps -ef | grep '26' " & ur cooperation is appreciated (0 Replies)
Discussion started by: AshAdmin
0 Replies

4. Shell Programming and Scripting

grep problem

hi, i need to get a count of the lines that contain 2 given patterns. eg: Line1 is <PATTERN1>blahblahblah</PATTERN1>then more text <PATTERN2>blahblahblah</PATTERN2> Line 2 is <PATTERN1>blahblahblah</PATTERN1>then some more text<INVALIDPATTERN>whatever</INVALIDPATTERN> I want to get a count of... (1 Reply)
Discussion started by: King Nothing
1 Replies

5. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

6. UNIX for Advanced & Expert Users

Problem with grep command options in Sunsolaris

Hi Experts I need the following output from grep command of Sunsolaris on a set of input files. Output:........ 1st search string from file1 2nd search string from file1 3rd search string from file1 1st search string from file2 2nd search string from file2 3rd search string from... (3 Replies)
Discussion started by: ks_reddy
3 Replies

7. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

8. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

9. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

10. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies
dhelp_parse(8)							Debian Linux manual						    dhelp_parse(8)

NAME
dhelp_parse - Debian online help parser SYNOPSIS
dhelp_parse [ -r | -i | -a doc-base_file | -d doc-base_file ] DESCRIPTION
This program is used by package developers to register the documents included in a package. In most cases it is called by install-docs (see doc-base package), which in turn is called from the postinst and prerm scripts of a Debian package. An index of the registered documents is written in the directory /usr/share/doc/HTML OPTIONS
-h,--help Displays the help page. -a Adds the documentation found in the given doc-base files to the dhelp database. -d Deletes the documentation found in the given doc-base files from the dhelp database. -i Does an incremental update of the documents index for all documentation added with the -a switch after the last index update. -r Ignored, kept for compatibility. PACKAGE DEVELOPERS
You should usually rely on install-docs to do the work for you, but if for some reason you want to use dhelp_parse directly (not recom- mended!), you have to call it like this: postinst if [ -x /usr/sbin/dhelp_parse ]; then dhelp_parse -a /var/lib/doc-base/documents/foo fi prerm if [ -x /usr/sbin/dhelp_parse ]; then dhelp_parse -d /var/lib/doc-base/documents/foo fi Note that /var/lib/doc-base/documents/foo has to be a valid doc-base file (see doc-base documentation). SEE ALSO
dhelp(1), install-docs(8) AUTHOR
This package was written by Esteban Manchado Velazquez (zoso@debian.org). Debian 29 May 2008 dhelp_parse(8)
All times are GMT -4. The time now is 06:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy