Sponsored Content
Full Discussion: Searching a string in a file
Top Forums Shell Programming and Scripting Searching a string in a file Post 302326653 by badrimohanty on Thursday 18th of June 2009 05:51:02 PM
Old 06-18-2009
Thanks

Thanks a lot @vgersh99 and @summer_cherry
I really appreciate the help you people have provided...

---------- Post updated at 05:51 PM ---------- Previous update was at 10:56 AM ----------

Hi,

I implemented the code as below. I'm facing some issue.

Here is my script:
testScript.sh
---------------
#!/bin/sh
arg_1=$1
echo "arg passed by user is:${arg_1}"
mapping=$(awk -F= -v name=${arg_1} '$1 == name {value=$2;exit} END { print (value)?value:"not found"}' testing.conf)
echo "mapping is $mapping"
if [ "${mapping}" = "not found" ]; then
echo "mapping passed as argument is not correct"
help
exit 1
fi

key=param_file_${mapping}
echo "key:${key}:"
param_file=`grep '${key}=' testing.conf | awk -F"=" '{print $2}'`
echo "param file is:${param_file}"

--------------------------------------------------------------------

The config file is as below:
testing.conf:
---------------
ram=219
param_file_219=/home/testDir
-----------------------------------------------------------------------
Now when I run the script as ./testScript.sh ram the output I get is as below:

output
--------------------
arg passed by user is:ram
mapping is 219
:eySmiliearam_file_219
param file is:

Could anyone kindly let me know what's wrong in the script?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

searching for a string though file system

Is there a way to search an entire file system for the occurance of a string..... other than grep. I have a large directory structure and I'm not certain that grep <string> */*/*/*... is all that effective - especially as I can't be sure of the number of levels to go down without heaps of... (3 Replies)
Discussion started by: peter.herlihy
3 Replies

2. Shell Programming and Scripting

Complicated string searching in a file

Hi folks, Following a part of opmn.xml file: <process-type id="OC4J_RiGHTv_PLATOR81" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (5 Replies)
Discussion started by: nir_s
5 Replies

3. Shell Programming and Scripting

Perl: searching for a string in a file...

Hi All, I need to search for a string in a file that I've opened and base a decision on the result. The logic is this: "if the word 'Shared' appears on the first line then do this on the whole file else do this on the whole file " The code I currently have isn't working:... (4 Replies)
Discussion started by: pondlife
4 Replies

4. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

5. UNIX for Dummies Questions & Answers

searching for a string in a file

I need to search for a specific string in a file and if this string exist I need to replace it with something else. I am not sure how I could do this, using an if statement. (2 Replies)
Discussion started by: ROOZ
2 Replies

6. Shell Programming and Scripting

searching each file for a string

Hi Guys... I want to search for each file that contains a particular string. e.g find . -print | xargs grep -i string_name Now my issue is the files that I search in are gzipped. Will I be able to find the string, using the above commands, even if the files are gzipped? Please... (2 Replies)
Discussion started by: Phuti
2 Replies

7. Shell Programming and Scripting

Searching for a specific string in a file

Hi I am trying to search for a certain set of patterns within a file, and then perform other commands based on output. testfile contents: password requisite pam_cracklib.so lcredit=-1 ucredit=-1 ocredit=-1 script: D="dcredit=-1" if then echo $D exists else echo $D doesnt... (8 Replies)
Discussion started by: bludhemn
8 Replies

8. Shell Programming and Scripting

Searching a string in a file using perl

Hi I would like to read a file using perl and search for a string (last entry). Then read that into an array and do further grep File content for ex: comp=a,value=30,runtime=12,type=lic comp=d,value=15,runtime=2,type=lic comp=a,value=90,runtime=43,type=lic... (1 Reply)
Discussion started by: vivek_damodaran
1 Replies

9. Shell Programming and Scripting

Searching a string stored in other file

I need to design a script which can do the following: I have two files abc.txt and constant.hmtl abc.txt contains some 5 string that I need to see if they exist in contants.html. Constants.hmtl is a very large file around 800 lines. I want to search all the strings present in file... (8 Replies)
Discussion started by: hemasid
8 Replies

10. Shell Programming and Scripting

Searching a string in a particular file name

Hello, I have a file name like FIRST_DPF_DAILY_CUST_0826152322.txt i need to extract the string after the third "_" underscore upto timestamp ends i.e CUST_0826152322 can anyone help me with the code Thank you! Regards Srikanth Sagi (3 Replies)
Discussion started by: srikanth_sagi
3 Replies
WCTRANS(3)						     Linux Programmer's Manual							WCTRANS(3)

NAME
wctrans - wide character translation mapping SYNOPSIS
#include <wctype.h> wctrans_t wctrans(const char *name); DESCRIPTION
The wctrans_t type represents a mapping which can map a wide character to another wide character. Its nature is implementation dependent, but the special value (wctrans_t)0 denotes an invalid mapping. Nonzero wctrans_t values can be passed to the towctrans function to actually perform the wide character mapping. The wctrans function returns a mapping, given by its name. The set of valid names depends on the LC_CTYPE category of the current locale, but the following names are valid in all locales. "tolower" - realizes the tolower(3) mapping "toupper" - realizes the toupper(3) mapping RETURN VALUE
The wctrans function returns a mapping descriptor if the name is valid. Otherwise it returns (wctrans_t)0. CONFORMING TO
ISO/ANSI C, UNIX98 SEE ALSO
wctrans(3) NOTES
The behaviour of wctrans depends on the LC_CTYPE category of the current locale. GNU
1999-07-25 WCTRANS(3)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy