SH Script for file name wildcards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SH Script for file name wildcards
# 1  
Old 02-15-2011
SH Script for file name wildcards

Does anyone know how I would go about inserting text at the beginning of a file with the file name containing a daily time stamp? Essentially I need to find the file name using a wild card, and then insert 3 lines of text - one of which is the processing date. Help please!?
# 2  
Old 02-15-2011
Hello and welcome to the forum.

The following may not be exactly what you want, but it should give you an idea of at least one possible approach. An example of how to add a couple of lines with a file's name (stored in a shell variable) and a current timestamp to the beginning of a file:
Code:
f=filename
ed -s "$f" <<EOED
1i
FILENAME: $f
TIMESTAMP: $(date)
.
w
q
EOED

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wildcards in file input to a script?

I have four files: test test2 test3 test4 I have this simple script: #!/bin/bash ls $1 Why does ./the_script.sh test* only list the first file, when a normal ls test* would list all four? What do I need to change in the script to be able to use wildcard? (12 Replies)
Discussion started by: KidCactus
12 Replies

2. UNIX for Advanced & Expert Users

Wildcards

These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all. GNU/Linux Command-Line Tools Guide - Wildcards GREP (1 Reply)
Discussion started by: cokedude
1 Replies

3. Shell Programming and Scripting

Check for file existence using wildcards

I am using the following command to check for files on a Unix (Solaris 9) and on Linux: if (-r *.) then echo " las file found" else echo " no las file found" endif If no las file is present, the "no las file found" message is displayed. If a las file is present, however, I get... (9 Replies)
Discussion started by: phudgens
9 Replies

4. UNIX for Dummies Questions & Answers

Running script on SFTP server, RMDIR and RM with wildcards

Im going insane trying to figure out what i consider a basic command on an SFTP server... Im trying to download all files from a directory *done* then remove all the files (and sometimes folders that contain files) i have downloaded on the remote directory... the command i would normally... (2 Replies)
Discussion started by: mokachoka
2 Replies

5. Shell Programming and Scripting

Perl script to search and extract using wildcards.

Good evening All, I have a perl script to pull out all occurrences of a files beginning with xx and ending in .p. I will then loop through all 1K files in a directory. I can grep for xx*.p files but it gives me the entire line. I wish to output to a single colum with only the hits found. ... (3 Replies)
Discussion started by: CammyD
3 Replies

6. Shell Programming and Scripting

How to chk the file name using wildcards??

Hi, I need to find a file with name xyz.mno.1234235.msg Here the numbers can be anything and is not fixed. But the first 6 characters are fixed ie, xyz and mno are fixed and wont change. Actually this file comes to this directory every week with only the number part changing. How is it... (7 Replies)
Discussion started by: RRVARMA
7 Replies

7. Shell Programming and Scripting

Use wildcards in a script

Hello I have this script: #!/bin/ksh INPUTFILE=$1 TEMPFILE=$INPUTFILE.$$ OUTPUTFILE=$INPUTFILE.new # nr of arguments has to be 1 if then echo "\nUsage: $0 inputfile\n" return 1 fi # inputfile must exist and be readable if then (13 Replies)
Discussion started by: emferrari
13 Replies

8. UNIX for Dummies Questions & Answers

File names based off of wildcards

Hello all- First post, so just to forewarn you: I know enough about Perl and the Terminal to get myself into trouble, not quite enough to always get out. I'd like to know if it is possible to, from the command prompt, use a wild-card to declare the names of files for input and then use the... (1 Reply)
Discussion started by: tcquad
1 Replies

9. UNIX for Dummies Questions & Answers

script for deletion using wildcards

find ./ -name t\* | sed "s@^./@@" > .filestobedeleted j=$(wc -l < .filestobedeleted) typeset -i cnt=0 typeset -i i=0 while read line do myarray=$line ((cnt = cnt + 1)) done < .filestobedeleted while (1 Reply)
Discussion started by: aishu
1 Replies

10. UNIX for Dummies Questions & Answers

ls with wildcards

ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this ls s*.dat > file_names.txt can't figure out whats wrong with that line, any ideas? thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies
Login or Register to Ask a Question