scripting help with touch and sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scripting help with touch and sed
# 1  
Old 02-14-2005
scripting help with touch and sed

Hello, I am trying to write a simple script to wake up every 300 seconds and look for a new file in a directory (e.g., "G102005"), remove the "G" from the file name, then print the new filename.

Here's what I've got so far. I'm new at this so please forgive the errors or misuse of syntax. It should be pretty clear what I'm trying to do. If possible please make corrections rather than just tell me what's wrong.

Thanks in advance!
alexkav

#!/bin/ksh
touch newtime
sleep 300
NEW=`find . -type f -name "G*" -newer newtime`
if [ ! -f $FILE ]
exit
else
sed -e 's/G//g' $NEW >FILE
echo $FILE
mv newtime oldtime
# 2  
Old 02-14-2005
so far....

Here is what I came up with so far.

Code:
#!/bin/ksh
touch newtime
sleep 10
NEW=`find . -type f -name "G*" -newer newtime`

if [ $NEW="" ]; then
	echo "bombing"
	exit 1
else
	echo "sedding"
	echo $NEW
	
	echo $NEW > temp
	sed -e 's/G//g' temp > FILE
	
	mv newtime oldtime
	rm -f temp
	
	exit 0
fi

# 3  
Old 02-14-2005
file timestamps

I was using a time of 10
for debugging, but maybe thats too soon. I don't know the
intervals of file timestamps. will look into it.
# 4  
Old 02-14-2005
I think this will do it

Code:
#!/bin/ksh

touch newtime
sleep 300

NEW=`find . -type f -name "G*" -newer newtime`
echo $NEW

if [ -z $NEW ]; then
	echo "bombing"
	exit 1
else
	echo "sedding"
	echo $NEW
	
	echo $NEW > temp
	sed -e 's/G//g' temp > FILE
	
	mv newtime oldtime
	rm -f temp
	
	exit 0
fi

# 5  
Old 02-14-2005
gjduff - thanks

gjduff, thanks alot for your help. I made a small change to your script to get rid of the temp part, since I don't want to write anything to the dir. How can I get rid of the "./" in the output? (see below):

sedding...
./203040

Also, instead of making the script exit if it doesn't detect a new file, how can I make it keep checking the dir?

Thanks again for your help,
alexkav

#!/bin/ksh
touch newtime
sleep 10
NEW=`find . -type f -name "G*" -newer newtime`
echo $NEW
if [ -z $NEW ]; then
echo "bombing..."
exit 1
else
echo "sedding..."
echo $NEW | sed -e 's/G//g' FILE
echo $FILE
mv newtime oldtime
exit 0
fi
# 6  
Old 02-14-2005
Oops, hang on. I think my removing the temp did something bad. Let me try again...
# 7  
Old 02-14-2005
Ok, this is better. Thanks again.

#!/bin/ksh
touch newtime
sleep 10

NEW=`find . -type f -name "G*" -newer newtime`

if [ -z $NEW ]; then
echo "bombing..."
exit 1

else
echo "sedding..."

FILE=`echo $NEW | sed -e 's/G//g'`
echo $FILE

mv newtime oldtime
exit 0
fi
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help shell scripting using awk or sed or other

I need to create a script to change a file depending of 3 conditions using a target as parameter... first condition <chamada> <numeroTerminalOriginador>CALLER</numeroTerminalOriginador> <imeiOriginador></imeiOriginador> <cgiPrimeiraErbOriginador></cgiPrimeiraErbOriginador>... (2 Replies)
Discussion started by: poulis
2 Replies

2. Shell Programming and Scripting

Need help with awk and sed scripting

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

3. Shell Programming and Scripting

Need help with sed scripting

Hi expert, i need URGENT help in bash shell scripting using sed: i woud like to search for the word XMLRPC which is at theend of the line below in up2date file. Once found or match serverURL=https://redhat.com/XMLRPC replace with myserver.com like this ... (1 Reply)
Discussion started by: lamoul
1 Replies

4. Shell Programming and Scripting

Sed scripting issue

Hi all! I was wondering if anyone could help suggest some solutions to an issue i'm having using the Sed command. I'm still a relative novice at this, but slowly learning and enjoying the power of batch processing. I am using Sed to extract values from a .txt file containing hundreds of... (2 Replies)
Discussion started by: StudentFitz
2 Replies

5. Shell Programming and Scripting

Shell Scripting -- sed

Hi, In one of my scripts, I am using sed to do an expression replacement. The code in the script is as under sed "s|MY_INP_Lab=""|MY_INP_Lab="${2}"|" file1, where $2=xyz_abc_mbk The EXPECTED output is in file1, all the instances ofMY_INP_Lab="" shall be replaced by... (2 Replies)
Discussion started by: vivekmattar
2 Replies

6. Shell Programming and Scripting

sed scripting help need

hi all, i want to display output of sar, whichever idle time is less than 30%..i want to add HI and BYE at the starting and ending of the line. For an example: sar Linux 2.6.9-78.0.1.ELsmp (hostname) 07/10/2009 07:10:01 AM CPU %user %nice %system %iowait %idle... (7 Replies)
Discussion started by: raghur77
7 Replies

7. UNIX for Dummies Questions & Answers

Touch all files and subdirectories (recursive touch)

I have a folder with many subdirectories and i need to set the modified date to today for everything in it. Please help, thanks! I tried something i found online, find . -print0 | xargs -r0 touch but I got the error: xargs: illegal option -- r (5 Replies)
Discussion started by: glev2005
5 Replies

8. Shell Programming and Scripting

SED scripting select

Say I have a file 'example.txt' with these lines of code in it: hello:anddasd:cheese:gerg whatever:sdadsa:asdfasdfa:wwew hmmmm:something:gfhfhgf:sdasdas Question: 1. How would I write a script which is able to take all the words before the first ':'? 2. How would I write a script which is... (6 Replies)
Discussion started by: i_am_a_robot
6 Replies

9. Shell Programming and Scripting

scripting with awk and sed

hey all, i was just wondering if it was possible to to get data from user input , and parse it through sed to remove or add what that user has entered into a flat file? do i need awk ? any help is greatly appreciated ~shan2on (2 Replies)
Discussion started by: shan2on
2 Replies

10. Shell Programming and Scripting

Help on SED AWK in shell scripting

Hi, I have a script abc.sql which contains a word 'timestamp'. I have another script xyz.txt genrated everyweek, which has a new timestamp value every week. How do I replace the word 'timestamp' in script abc.sql with the value mentioned in the script xyz.txt, so that I can run the script... (3 Replies)
Discussion started by: kaushys
3 Replies
Login or Register to Ask a Question