Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to Grep second word in config file using parameter? Post 303019415 by saranath on Friday 29th of June 2018 12:39:55 AM
Old 06-29-2018
How to Grep second word in config file using parameter?

Currently i am building one script to grep region records in the config file based on parameter and then i am creating a text file with that out put and i am reading the source file path in that out put file
now i need to pass one more parameter like module based upon that it has to create a text file

my script
Code:
#!/bin/bash

SOURCE_CONF="./test.properties"

#input region name
region="$1"
echo $region
cwd=$(pwd)
calu=$(grep $region test.properties > ab.txt)

IFS=$'\n'

#loop to read the config one line at a time
while read p; do
    echo $p

    a=($(echo "$p" | tr '|' '\n'))
    echo "Region is:" "${a[0]}"
    echo "path is:""${a[3]}"
    path="${a[3]}"
    #remove white space before path
    echo $cwd
    NO_LEAD_SPACE="$(echo -e $path | tr -d '[:space:]')"
    echo "path is:"$NO_LEAD_SPACE
# change to path spacified in the config file
    sh -c 'cd $NO_LEAD_SPACE && echo "in the subshell" && echo $pwd && echo "exit subshell" && exec pwd'
    echo $cwd
    echo "--------------------"
done < ab.txt

echo "abc"



my config file

Code:
region | Module |country code | filepath |filename


APJ | WDMD | MYS |/c/Users/vattikun/desktop | MYS*ADPGV*.XML
APJ | WDED | EUR|/c/Users/vattikun/desktop/Payroll Support | EUR*ADPGV*.XML

APJ | WDMD | RER|/c/Users/vattikun/desktop/Payroll Support | RER*ADPGV*.XML

APJ | WDJD | EYZ|/c/Users/vattikun/desktop/Payroll Support | EYZ*ADPGV*.XML


EMA | WDMD | AUS|/c/Users/vattikun/desktop | AUS*ADPGV*.XML
EMA | WDMD | AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML

AMS | WDMD |ITI| /c/Users/vattikun/desktop | ITI*ADPGV*.XML
AMS |WDMD |AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML

ETIME | WDMD |ADP /c/Users/vattikun/desktop | ADP_WDET_JOBCODE*.XML
ETIME | WDMD |AEP| /c/Users/vattikun/desktop | AEP_WDET_JOBCODE*.XML


Last edited by Scrutinizer; 06-29-2018 at 04:37 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep all records in a file and get a word count -perl

Hi, I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script thanks (4 Replies)
Discussion started by: meghana
4 Replies

2. Shell Programming and Scripting

how to grep for a word in a log file..

Hi All, I have a log file which is storing a backup time stamps information in it. (pasted below) 20081006210008 0 20081006211910 20081006222824 0 20081006224758 20081007210049 0 ... (2 Replies)
Discussion started by: suri.tyson
2 Replies

3. Shell Programming and Scripting

grep second word in a file

How do I match second word and then print that line to output For eg: My file has following text and I want to check if second word is n then I want to print entire line . xytxti8naclip y xytxt32bpsimple y xytxt32bpna n xytxti16nae y xysmps32bpp031_bst n... (7 Replies)
Discussion started by: pitagi
7 Replies

4. UNIX for Dummies Questions & Answers

Grep the word at the end of the file

I need to grep the word "hello" in each and every file. This word will be placed either at the end of the file or before the end of the file. Ex: file1: file2: afdsaf dsfalk fdsa weruoi sdaf erwqiuo fsdaf ... (5 Replies)
Discussion started by: sivakumar.rj
5 Replies

5. Shell Programming and Scripting

key word parameter

cat shell_script.ksh x=$A y=$B export x export y echo $x echo $y when i am running this with a command ksh shell_script.ksh -A 10 -B 20 its not showing anything .... could you let me know how i can use key word type paramter (2 Replies)
Discussion started by: dr46014
2 Replies

6. Shell Programming and Scripting

Bash parameter expansion from a config file

Hi - I am trying to do a simple config file with known variable names in it, e.g.: contents of config file a.conf: -a -b $work -c $host simplified contents of bash script file: work='trunk' host='alaska' opts=$(tr '\n' ' ' < a.conf) opts="$opts $*" mycommand $opts arg1 arg2 The... (3 Replies)
Discussion started by: mrengert
3 Replies

7. Shell Programming and Scripting

How can I just grep one instance of a word in the file

I want to grep some information out of the dmidecode but when I type dmidecode | grep Memory I get several instances of the word. Is there a way I can just choose which instance I want to display? (8 Replies)
Discussion started by: jcnewton13
8 Replies

8. Shell Programming and Scripting

How to pass two word parameter

Hi, How to pass parameter to run folloing script? #parameters are div, dept, style U run_convert_pdm.ksh Mens 44 7542 U run_convert_pdm.ksh "Mens Knit" 44 7541 The first command works fine but the second needs to have two words together , it does not work even if I have used double... (15 Replies)
Discussion started by: sandy162
15 Replies

9. Shell Programming and Scripting

Using grep and a parameter file to return unique values

Hello Everyone! I have updated the first post so that my intentions are easier to understand, and also attached sample files (post #18). I have over 500 text files in a directory. Over 1 GB of data. The data in those files is organised in lines: My intention is to return one line per... (23 Replies)
Discussion started by: clippertm
23 Replies

10. Shell Programming and Scripting

Shell script example to Grep matching word from file

Hi expert, Need help in shell script. a.txt file output is below i would like to grep 3 line and 1st column value which is admin\22226 only and not full line. i only know admin word as 22226 can come anything with admin\ in file. also after fetching it i would like to use this... (1 Reply)
Discussion started by: kuljeetpal
1 Replies
curl-config(1)							curl-config manual						    curl-config(1)

NAME
curl-config - Get information about a libcurl installation SYNOPSIS
curl-config [options] DESCRIPTION
curl-config displays information about the curl and libcurl installation. OPTIONS
--ca Displays the built-in path to the CA cert bundle this libcurl uses. --cc Displays the compiler used to build libcurl. --cflags Set of compiler options (CFLAGS) to use when compiling files that use libcurl. Currently that is only the include path to the curl include files. --checkfor [version] Specify the oldest possible libcurl version string you want, and this script will return 0 if the current installation is new enough or it returns 1 and outputs a text saying that the current version is not new enough. (Added in 7.15.4) --configure Displays the arguments given to configure when building curl. --feature Lists what particular main features the installed libcurl was built with. At the time of writing, this list may include SSL, KRB4 or IPv6. Do not assume any particular order. The keywords will be separated by newlines. There may be none, one, or several keywords in the list. --help Displays the available options. --libs Shows the complete set of libs and other linker options you will need in order to link your application with libcurl. --prefix This is the prefix used when libcurl was installed. Libcurl is then installed in $prefix/lib and its header files are installed in $prefix/include and so on. The prefix is set with "configure --prefix". --protocols Lists what particular protocols the installed libcurl was built to support. At the time of writing, this list may include HTTP, HTTPS, FTP, FTPS, FILE, TELNET, LDAP, DICT. Do not assume any particular order. The protocols will be listed using uppercase and are separated by newlines. There may be none, one, or several protocols in the list. (Added in 7.13.0) --static-libs Shows the complete set of libs and other linker options you will need in order to link your application with libcurl statically. (Added in 7.17.1) --version Outputs version information about the installed libcurl. --vernum Outputs version information about the installed libcurl, in numerical mode. This outputs the version number, in hexadecimal, with 8 bits for each part; major, minor, patch. So that libcurl 7.7.4 would appear as 070704 and libcurl 12.13.14 would appear as 0c0d0e... Note that the initial zero might be omitted. (This option was broken in the 7.15.0 release.) EXAMPLES
What linker options do I need when I link with libcurl? $ curl-config --libs What compiler options do I need when I compile using libcurl functions? $ curl-config --cflags How do I know if libcurl was built with SSL support? $ curl-config --feature | grep SSL What's the installed libcurl version? $ curl-config --version How do I build a single file with a one-line command? $ `curl-config --cc --cflags` -o example example.c `curl-config --libs` SEE ALSO
curl(1) Curl 7.54.0 February 03, 2016 curl-config(1)
All times are GMT -4. The time now is 11:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy