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
asadmin-add-resources(1AS)					   User Commands					asadmin-add-resources(1AS)

NAME
add-resources - registers the resource in the XML file specified SYNOPSIS
add-resources --user admin_user [--password admin_password][--host localhost] [--port 4848] [--secure|-s] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=true] xml_file_path Registers the named resource in the XML file specified. The xml_file_path is the path to the XML file containing the resources to be regis- tered. The DOCTYPE should be specified as install_dir/lib/dtds/sun-resources_1_0.dtd in the resources.xml file. This command is supported in remote mode only. OPTIONS
--user authorized domain application server administrative username. --password password to administer the domain application server. --host machine name where the domain application server is running. --port port number of the domain application server listening for administration requests. --secure if true, uses SSL/TLS to communicate with the domain application server. --passwordfile file containing the domain application server password. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. Default is false. --echo setting to true will echo the command line statement on the standard output. Default is false. --interactive if set to true (default), only the required password options are prompted. OPERANDS
xml_file_path path to the XML file containing the resource(s) to be registered. Example 1: Using add-resources asadmin> add-resources --user admin --passwordfile passwords.txt --host localhost --port 4848 resource.xml Command add-resources executed successfully Where: resource.xml is the resource file containing resources to be created. EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-create-jdbc-connection-pool(1AS), asadmin-create-jdbc-resource(1AS), asadmin-create-jms-resource(1AS), asadmin-create-jndi- resource(1AS), asadmin-create-javamail-resource(1AS), asadmin-create-persistence-resource(1AS), asadmin-create-custom-resource(1AS) J2EE 1.4 SDK March 2004 asadmin-add-resources(1AS)
All times are GMT -4. The time now is 02:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy