Very small prob, But I m stuck !!!


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Very small prob, But I m stuck !!!
# 1  
Old 11-10-2010
Question Very small prob, But I m stuck !!!

Hi All,
I m trying to write a small utilities to help me.
I need to create a shell script to which if I give two filenames it will create a some.diff file from that.

I know its very simple, but I am stuck
here is code I have written.
Code:
  1 #this is is diff file generator
  2 
  3 echo $1 $2  
  4 #echo $#
  5 echo script $0 is running in `pwd` directory diff file will be generated in     current directory.
  6 
  7 echo first file enter as $1
  8 echo second file entered as $2
  9 #echo $filename
 10 DIFF_FILENAME=`echo $filename | awk -F"."'{print $1}'`
 11 echo $DIFF_FILENAME
 12 #read DIFF_FILE_NAME 
 13 #diff $1 $2 >

in the line number 10, I am just trying to get diff file name from first file name.
let say have filename1.c, I want the name of diff file as filename1.diff
some how I am not able to cut the name before dot (.) and append the .diff to it.
Anyone please help me out, where I m making mistake.
Thanks in advnace.

~reverser

Last edited by Scott; 11-10-2010 at 03:30 PM.. Reason: Code tags
# 2  
Old 11-10-2010
It's helpful, when you post problems, to say what it is doing, not just what you want it to do. I had to type out the code myself to see what was going wrong...

When I try your code awk prints an error message and usage instructions. Looks like you forgot a space between " and ', when I add it awk does as expected.

Depending on your shell there may be much more efficient ways to do this, like:

Code:
IFS="." read file ext <<< "${filename}"

If you're calling awk, cut, sed, perl, etc. to process single lines of text, that's probably not the best way to do it. awk is an entire complex language by itself, and any of these can process more than one line, so it's overkill and slows your script way down.
# 3  
Old 11-10-2010
Code you have published that worked too well
even that solved the extension problem by itself

but that awk thing is not working I put that space in between, but still that DIFF_FILENAME is Empty string.

any guess about that .
# 4  
Old 11-10-2010
Hi.

I'm missing the bit where you set filename...

Code:
DIFF_FILENAME=`echo $filename | awk -F"."'{print $1}'`

# 5  
Old 11-10-2010
You have to assign the first parameter to the the variable filename before using it:
Code:
filename=$1
DIFF_FILENAME=${filename%.*}.diff

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Prob. with using as86

Hi, I have downloaded as86-0.16.17.tar file. When I umcompressed it I found it consisting of C source and header files. How can i create an executable for compiling assembly programs. Kindly help me with this. I am working on windows XP professional and system is HP DX 2700. Zulfi. (0 Replies)
Discussion started by: zak100
0 Replies

2. Solaris

mount prob

# mount /dev/dsk/c1d1s1 /mnt mount: /dev/dsk/c1d1s1 is not this fstype I tried to mount the above raw patition and it gave an error. but can someone help (3 Replies)
Discussion started by: seyiisq
3 Replies

3. Shell Programming and Scripting

sorting prob

my sample is 01012007 01022007 02022007 01032007 20022007 02032007 01092007 05022007 30022007 which is date in ddmmccyy format i try to sort like this sort -n +0.2 -0.5 +0.0 -0.3 file but the results are not correct pls help...... (3 Replies)
Discussion started by: paresh n doshi
3 Replies

4. UNIX for Advanced & Expert Users

NFS prob

Hi all, i want mount directory with permission #NFS Server = FreeBSD /etc/export = /data -alldirs -network 192.168.0.0 -mask 255.255.255.0 #NFS Client = Ubuntu 192.168.0.8:/data /dir nfs intr but i m unable to create folder in /dir whts the wrong? Please... (4 Replies)
Discussion started by: jagnikam
4 Replies

5. Shell Programming and Scripting

Sorting prob

Hi I have a directory having following three set of files as follows: test.20060804 test.20060801 test.20060802 I want to list the latest file which is less than 20060803. in this case, it will be test.20060802. How can i achieve the same? Any pointers to above will be appreciated. ... (7 Replies)
Discussion started by: Vikas Sood
7 Replies

6. Shell Programming and Scripting

prob with ssh

I am executing this on say host1 export dn=/home/abhi export fn=file\"*\" file_path=$dn/$fn set -A files $(ssh host2 "eval echo $file_path") echo files= ${files} So the purpose is to store in array "files" .. the o/p of cmd executed in host2... this script works fine if the files r... (1 Reply)
Discussion started by: abzi
1 Replies

7. UNIX for Dummies Questions & Answers

cronjob prob

Hi all I am getting the following error when i execute my cronjob : stty: : No such device or address stty: : No such device or address What could be the problem. Thanks Rahul (3 Replies)
Discussion started by: rahul123_libra
3 Replies

8. AIX

memory prob

There is problem in my system whenever i run a command lsattr -El mem0 it shows 3gb memory and when i run lscfg -vp | grep Size it shows 8 modules of 512 mb. it means it shows 4 gb how is it possible. (1 Reply)
Discussion started by: vjm
1 Replies

9. UNIX for Dummies Questions & Answers

grep prob

hi, how can i saerch for foll pattern the line contains many entries: xxx xxxx ddd ffff gggg 30% rr eeee eeee rrrr rrrr 100% rr eeee eeee rrrr rrrr 43% how can i display lines having size greater than 40%?what pattern shud i use in grep? thanks! regards vivek.s (1 Reply)
Discussion started by: vivekshankar
1 Replies

10. Shell Programming and Scripting

prob

When i am trying to $uncompress tress.dmp.Z I am getting tress.dmp.Z permission denied. What action i have to perform to unzip or uncompress It has rw-r--r-- permissions When i am trying to change the permissions chmod 744 it says. chmod: Warning: can't change tress.dmp.Z Just... (1 Reply)
Discussion started by: dreams5617
1 Replies
Login or Register to Ask a Question