testing length

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting testing length
# 1  
Old 02-09-2008
testing length

I've never tested file length with shell before and I'm having problems. What I'm doing is testing $filename and $filename.bak to see if there is a difference. so I use 'diff' for that and send it to an output file 'dif.txt'. Now I wanna see if the length of 'dif.txt' is zero or not. that's where i'm stuck. Here's what i gotSmilieusing /csh)

diff ${filename} ${filename}.bak > dif.txt
if ( test -z dif.txt )
echo "New Backup Not Needed"
cp ${filename} "${filename}.bak<DATE>"
echo "New Backup Created"

Also, I need assistance with proper input of todays DATE.
# 2  
Old 02-09-2008
Here is something which should work for you. You were not very clear on what you wanted to do with DATE so I just appended it to .bak


set filename=myfile
set date=`date +%Y%m%d`

diff ${filename} ${filename}.bak > dif.txt
if ( -z dif.txt ) then
   echo "New backup not needed"
   cp ${filename} "${filename}.bak.${date}"
   echo "New backup created on $date"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies

2. Shell Programming and Scripting

Testing the length of a string

Hello, Unix-Forums! Is there a command that can check how long a user-entered string is? Please don't give me a code, just the name of the command (playing around yourself is much more fun than just pasting code) edit: I'm sorry, first hit of the forum search gave me the answer. (1 Reply)
Discussion started by: intelinside
1 Replies

3. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

4. UNIX for Dummies Questions & Answers

Testing for non-zero length string

Hello, can someone please explain to me why this happens: myserver#echo "$nothing" myserver#if ; then echo "nothing is a zero length string"; fi nothing is a zero length string myserver#if ; then echo "nothing is also a non-zero length string, apparently"; fi nothing is also a non-zero... (5 Replies)
Discussion started by: longjon
5 Replies

5. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

7. Shell Programming and Scripting

need help testing for length of variable

Hello, I'm new to shell scripting and need a little help please. I'm working on a script that asks the user to input a name that can be 1 to 12 alphanumeric characters and can have dots(.) dashes(-) and spaces. I want to test that the answer is valid and if not make the user try again. I have no... (4 Replies)
Discussion started by: wlewis
4 Replies

8. UNIX for Dummies Questions & Answers

Sed working on lines of small length and not large length

Hi , I have a peculiar case, where my sed command is working on a file which contains lines of small length. sed "s/XYZ:1/XYZ:3/g" abc.txt > xyz.txt when abc.txt contains lines of small length(currently around 80 chars) , this sed command is working fine. when abc.txt contains lines of... (3 Replies)
Discussion started by: thanuman
3 Replies

9. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies
Login or Register to Ask a Question