Shell not parsing $ sign from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell not parsing $ sign from file
# 1  
Old 02-06-2012
Network Shell not parsing $ sign from file

PFB my shell script which reads a csv file to process it

Code:
###############################################
fn_java(){
        echo JAVA_TOP is $JAVA_TOP
        echo "cp $filename $filepath/$filename"
        cp $filename $filepath/$filename
}

#########################################
JAVA_TOP=/dcypri/applmgr/common/java
if [ -f DATA.csv ]
then
        while read myline
        do
        echo $myline
        filename="$(echo $myline | cut -d, -f1)"
        filepath="$(echo $myline | cut -d, -f2)"
        echo $filename
        echo $filepath
        if [ -f $filename ]
        then
         fn_java $filename $filepath

        fi
        done < DATA.csv
fi

And the data file contains two rows.
Code:
XXEasyShipPage.java,/dcypri/applmgr/common/java
XXEasyShipPage.java,$JAVA_TOP

It works perfectly for the first row, but not for the second row.
Code:
$JAVA_TOP point to /dcypri/applmgr/common/java

It literally tries to
Code:
cp XXEasyShipPage.java $JAVA_TOP/XXEasyShipPage.java

instead of
Code:
cp XXEasyShipPage.java /dcypri/applmgr/common/java/XXEasyShipPage.java


Last edited by Franklin52; 02-06-2012 at 06:51 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 02-06-2012
your JAVA_TOP variable must be set before the declaration of your fn_java(){ ... } function.
(if this is not sufficient, export it)

If you want to pass some argument to you fn_java function, you must refer to them as $1 $2 etc ... inside your fn_java function.
Code:
JAVA_TOP=/dcypri/applmgr/common/java
export JAVA_TOP
fn_java(){
        echo JAVA_TOP is $JAVA_TOP
        echo "cp $1 $2/$1"
        cp "$1" "$2/$1"
}

...

fn_java "$filename" "$filepath"

# 3  
Old 02-06-2012
Hi ctsgnb,

I have tried changing to $1, $2 as well as the $JAVA_TOP variable has been set. But still it is not working. When I echo $JAVA_TOP, it gives me the desired o/p, but cp doesnt work as it throws below error
Code:
XXEasyShipPage.java,$JAVA_TOP
XXEasyShipPage.java
$JAVA_TOP
JAVA_TOP is /dcypri/applmgr/common/java
cp XXEasyShipPage.java $JAVA_TOP/XXEasyShipPage.java
cp: cannot create regular file `$JAVA_TOP/XXEasyShipPage.java': No such file or directory


Last edited by Franklin52; 02-06-2012 at 06:51 AM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 02-06-2012
How does your current code look like ?

please provide the output of

Code:
cat yourscript

Please also provide cat DATA.csv

Last edited by ctsgnb; 02-06-2012 at 07:15 AM..
# 5  
Old 02-06-2012
one simple thing is before reading the file, replace the variable in the file.
Code:
sed "s:\$JAVA_TOP:$JAVA_TOP:" DATA.csv > /tmp/DATA.csv

read the value from "/tmp/DATA.csv" instead of "DATA.csv"

Last edited by Franklin52; 02-06-2012 at 09:10 AM.. Reason: Please use code tags for data and code samples, thank you
This User Gave Thanks to kalpeer For This Post:
# 6  
Old 02-07-2012
Kalpeer. Thanks for your reply. It worked, Smilie however the folder is not $JAVA_TOP always and will vary each time.
When I sed my filepath variable with same filepath variable, again i am not able to get it.

Is there a way to get this without hard-coding as $JAVA_TOP?
# 7  
Old 02-08-2012
Can somebody kindly help on this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to escape colon sign from variable in shell?

Hello, Below script works fine when I manually enter required information for each file. When it comes to shell in auto mode, it gives various errors. I am under ubuntu 14.04 / trusty. manual_run.sh: #!/bin/bash /usr/bin/ffmpeg -start_at_zero -copyts -i nicki.mp4 -c:v mpeg2video \ -b:v 500k... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Shell script not parsing complete file using AWK

Hi, I have shell script which will read single edi document and break data between ST & SE to separate files.Below example should create 3 separate files. I have written script with the below command and it is working fine for smaller files. awk -F\| -vt=`date +%m%d%y%H%M%S%s` \ ... (2 Replies)
Discussion started by: prasadm
2 Replies

3. Solaris

XML to Text file Parsing Using shell scripting

Hi, I want to parse an XML File using Shell Script preferably by using awk command, I/P file is : <gn:ExternalGsmCell id="016P3A"> <gn:attributes> <gn:mnc>410</gn:mnc> <gn:mcc>310</gn:mcc> <gn:lac>8016</gn:lac> ... (2 Replies)
Discussion started by: tech_frk
2 Replies

4. Shell Programming and Scripting

XML to Text file Parsing Using shell scripting

Hi folks, Need some help with XML to text file parsing , the following is the content of the XML File. <xn:SubNetwork id="SNJNPRZDCR0R03"> <xn:MeContext id="PRSJU0005"> <xn:VsDataContainer id="PRSJU0005"> <xn:attributes> ... (6 Replies)
Discussion started by: tech_frk
6 Replies

5. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

6. Shell Programming and Scripting

Remove # sign from the file

Hello Friends, i need help to remove "#" sign from a file. I want to remove the "#" marks just in the area mentioned in red. I am not so good in awk, this help would be deeply appreciated. thanks Ado trap = { # { # trap-community = SNMP-trap # hosts = hubble,... (14 Replies)
Discussion started by: asirohi
14 Replies

7. Shell Programming and Scripting

Help in parsing a CSV file with Shell script

I have a CSV file which contains number series as one of the fields. Some of the records of the field look like : 079661/3 I have to convert the above series as 079661 079662 079663 and store it as 3 different records. Looking for help on how to achieve this. Am a newbie at Shell... (10 Replies)
Discussion started by: mihirk
10 Replies

8. Shell Programming and Scripting

Shell script for parsing 300mb log file..

am relatively new to Shell scripting. I have written a script for parsing a big file. The logic is: Apart from lot of other useless stuffs, there are many occurances of <abc> and corresponding </abc> tags. (All of them are properly closed) My requirement is to find a particular tag (say... (3 Replies)
Discussion started by: gurpreet470
3 Replies

9. Shell Programming and Scripting

Parsing a file in Shell Script

Hi, I have a requirement. I have an application which can take a file as inputs. Now the file can contain any number of lines. The tool has to pick up the first uncommented line and begin processing it. For example the file could be like this: #MANI123|MANI1234 #MANI234|MANI247... (4 Replies)
Discussion started by: sendhilmani123
4 Replies

10. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies
Login or Register to Ask a Question