Script That Appends


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script That Appends
# 1  
Old 03-07-2008
Data Script That Appends

I am trying to write a bash script that takes a file as an argument and appends my name if this file ends in .txt... I am not sure how to do this though. Any help is greatly appreciated!
# 2  
Old 03-08-2008
Check this

Proabably lengthy and complicated but works

Run this Script

filename=$@
length=`echo $filename | wc -c`
length=`expr $length - 1`
length1=`expr $length - 3`
verify=`echo $filename | cut -b$length1-$length`

if [ "$verify" = ".txt" ]
then
echo "My name" >> $filename
else
echo "Cannot append My name"
fi
# 3  
Old 03-08-2008
Check for file extension of ".txt" Using expr regular expression

Code:
if expr $filename : '^.*\.txt$'
then
   echo "my name" >> $filename
fi

# 4  
Old 03-08-2008
Okay, I actually have figure out how to get this script to append my name to the file. Now I want to figure out how to prepend if the user inputs a "-p" flag and print files that I am appending if the user inputs a "-v" flag. This is my code thus far... The flags do not work.

Code:
if [ $@ = *.txt ] ; then

        mv $@ $@.Name

elif [ $1 = -p ] ; then

        mv $@ Name.$@

elif [ $1 = -v ] ; then

        echo $@

else

        echo "Error - Can Not Append"

fi

# 5  
Old 03-08-2008
Quote:
Originally Posted by GTRocker8824
I am trying to write a bash script that takes a file as an argument and appends my name if this file ends in .txt... I am not sure how to do this though. Any help is greatly appreciated!
Code:
#!/bin/bash
file=$1
case $file in 
 *.txt) newfile=${file%*.txt}"-myname.txt"
esac
mv $file $newfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. Shell Programming and Scripting

Ftp bash script appends to file using cron instead of coping new file

I have a bash script that is running a mysql query and creating a csv file with a time stamp. It then uploads that to a ftp server. Everything works great when I manually run it. But then I have a cron job set to run every monday, wednesday and friday at 5am est. When the cron job runs, it... (7 Replies)
Discussion started by: akallenberger
7 Replies

4. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

5. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

6. UNIX for Dummies Questions & Answers

echo appends to a read-only file

echo command can append to a read-only file too. If the file is read-only, with w flag removed, then even echo should not be able to append to the file. But it is possible. Can anybody explain the below behaviour? /root > echo 'sample text' > file /root > cat file sample text /root >... (2 Replies)
Discussion started by: anand_bh
2 Replies

7. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question