Extracting variable value from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting variable value from file
# 1  
Old 01-05-2012
Extracting variable value from file

Hi All

i have created a file as below
Code:
cat > REJ_FILE_LIST.dat
CUST.DAT,$ABC/TEST.DAT|$ABC/TEST1.DAT|$ABC/TEST2.dat
Ctrl+d

in another script the variable is set as
Code:
ABC='/data/proj/Cust'

the requirement is to read the second column from file REJ_FILE_LIST.dat which contains list of files delimited by '|' whose path is parameterised with variable ABC which is set in the script and from withing the script and i need to find total number of records contained by the list of files.

in the script i have used
Code:
FileLst=`cut -d, -f2,2 TEST.dat |tr '|' ' '` ----> To read the col 2
TotRecCnt=`wc -l $FileLst|tail -1|tr -d ' '|sed 's/[a-z,A-Z]//g'` ---->to fetch the total record count of the file list

but the problem is the variable ABC is not being replaced by its value instead the whole of column 2 is being considered as string (along with $)

so TotRecCnt is parsed as
Code:
wc -l $ABC/TEST.DAT $ABC/TEST1.DAT $ABC/TEST2.dat

Please help


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 01-05-2012 at 10:42 AM.. Reason: code tags, see PM
# 2  
Old 01-05-2012
Code:
# ABC='/data/proj/Cust'
# cat REJ_FILE_LIST.dat
CUST.DAT,$ABC/TEST.DAT|$ABC/TEST1.DAT|$ABC/TEST2.dat
# IFS="|" read a a b <REJ_FILE_LIST.dat
# echo $a
$ABC/TEST1.DAT
# eval echo $a
/data/proj/Cust/TEST1.DAT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting substring from variable

Hi All, I'm facing issue wherein I have 2 character string like 'CR' and 'DR' and I want to extract just 1st character but am unable to do it. I tried below options but they are returning me 2nd character only, var="CR" echo ${var:1} returns just "R" echo ${var:0} returns "CR" ... (5 Replies)
Discussion started by: arvindshukla81
5 Replies

2. Shell Programming and Scripting

Extracting value of a variable

Hi Experts, I have one scenario here. I want to extract the value of a variable as mentioned below using a shell script (bash). I am having a file say File A. Inside the file, I have a variable assigned a string value. File A: Var1="value of the variable" In a particular script... (14 Replies)
Discussion started by: guknvivek
14 Replies

3. Shell Programming and Scripting

Extracting substrings from a string of variable length

I have a string like Months=jan feb mar april x y .. Here the number of fields in Months is not definite I need to extract each field in the Months string and pass it to awk . Don't want to use for in since it is a loop . How can i do it (2 Replies)
Discussion started by: Nevergivup
2 Replies

4. Shell Programming and Scripting

Extracting characters and storing in some variable

eg: ./myProgram.sh filename.cpp I want to remove the :".cpp" extension from the filename.cpp expected output: filename (3 Replies)
Discussion started by: umesh314
3 Replies

5. Shell Programming and Scripting

extracting Number variable and the following digits.

HI all, I have output of something like this: crab: ExitCodes Summary >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 List of jobs: 1-12 See https:///twiki/something/ for Exit Code meaning crab: ExitCodes Summary >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 List of... (20 Replies)
Discussion started by: emily
20 Replies

6. Shell Programming and Scripting

Extracting data from SQL using a variable from a file

Though, its not new, I am a newbie to shell scripting. Please help me with the below. There are two steps. First one is to read a table and create a file with the distinct values. I am able to get this done. Second step is to read the file (which has the single value, like a number) and... (1 Reply)
Discussion started by: singas1
1 Replies

7. Shell Programming and Scripting

Extracting a word from a variable

Hi Guys, Need you quick assistance on the below, trying to extract a word from a variable i.e. acmi101acmi102acmi103acmi104 When i use the following code awk '{gsub(/cmi102/,"")};1' it leaves a space in the variable, need to get rid of the space that it leaves. Any ideas. the above... (3 Replies)
Discussion started by: eo29
3 Replies

8. Shell Programming and Scripting

extracting value in variable??

Hi in Below example. i want "n = aa.txt.gz" ????????????? plz help m=aa.txt n=echo`gzip $m` echo $n (1 Reply)
Discussion started by: manish.s
1 Replies

9. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question