Shell Script to store contents of multiple files into one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to store contents of multiple files into one
# 1  
Old 08-19-2011
Shell Script to store contents of multiple files into one

Hi,

I"m writing a script to store all the contents of multiple files with different file names into one single file.
I am giving in only last modified date of file in a folder. The below script gives a list of just one file based on the input date i give which is taken as string variable. I want to list and store the same file listed, and file which is before and after the above said date. For ex:
If i need a file starting with identity_*(timestamp) on a date 17th Aug. I give input as 17th Aug as input. It should save all the files in the directory which start with identity_* for 16th Aug, 17th Aug, 18th Aug in a file.

Code:
#!/bin/bash
#date to match
DATE="$1"

# file, it can be wild cards too
FILE="$2"
# List of file to edit
FLIST=""
for f in $FILE
do
FDATE=$(ls -l $f | awk '{ print $7 $6 }')
if [ "$DATE" == "$FDATE" ];then
FLIST="$FLIST $f"
fi
done

# just display list of files and let the use do

[ "$FLIST" != "" ] && echo $FLIST || echo "Sorry no files found to match $DATE date."

Thanks,

Ash
# 2  
Old 08-19-2011
It really a pain because of 1, 30, 31-th days of monthes (don't count February and leap years). If you need accuracy you can use GNU date with -d option and appropriate format for input and output dates. Or use time functions in gawk or perl or ruby or python. If not - make an associative array (bash 4.x) with Jan = 31, Feb = 28, etc. and work with it.
It's just a simple but boring programming task.
# 3  
Old 08-20-2011
Is it possible to search for a multiple strings (like an OR statement) (08T12\|08T13\|) in all the files of the directory and then copy the grep results in a file ??
I want to know if any regular expression would be useful.... i'm a total newbie to shell scripting. Any help is appreciated.

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to store count of multiple queries in variables in a shell script?

how to store the count of queries in variables inside a filein shell script my output : filename ------- variable1=result from 1st query variable2=result from 2nd query . . . . (3 Replies)
Discussion started by: sanvel
3 Replies

2. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

3. Shell Programming and Scripting

How to store results of multiple sql queries in shell variables in ksh?

Hi, I have a script where I make a sqlplus connection. In the script I have multiple sql queries within that sqlplus connection. I want the result of the queries to be stored in shell variables declared earlier. I dont want to use procedures. Is there anyway else. Thanks in advance.. Cheers (6 Replies)
Discussion started by: gonchusirsa
6 Replies

4. UNIX for Dummies Questions & Answers

Writing a loop to manipulate a script and store it in multiple output files

I have a script where the the 9th line looks like this: $filename=sprintf("250.1chr%d.ped", $N); I want to modify this script 1000 times, changing 250.1chr%d.ped to 250.2chr%d.ped, 250.3chr%.ped.......and so on all the way to 250.1000chr%d.ped and store each output in files called ... (4 Replies)
Discussion started by: evelibertine
4 Replies

5. Shell Programming and Scripting

Empty Multiple files contents

I would like to empty multiple files contents (without delete the file) which have similar name to begin with. e.g. log1.txt log2.txt log3.txt log4.txt I know cat /dev/null will do the job but that only apply to a single file. But when i tried cat /dev/null > {} \; that doesnt do... (7 Replies)
Discussion started by: kin
7 Replies

6. Shell Programming and Scripting

Renaming multiple files with a shell script

Hey guys, I'm really new to UNIX and shell scripting in general. For my internship I need to rename a bunch of files. Specifically, I need to change the first letter of each of the files to lowercase and I have to change the endings so they all basically look like "file_cone.jpg". I know I... (4 Replies)
Discussion started by: jjzieve
4 Replies

7. Shell Programming and Scripting

Rename contents inside multiple files

Hi, I have 100 files in a directory. Each file have the following format >CtbRe01234 fdfjdhfkdfkd >CtL2B0456 gjfgfkgjfkgjfk >CmdrE05768 fghdjskksllfkLike this I have many files in the directory. What I want is; rename the header content in each file such that the above file... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

8. Shell Programming and Scripting

shell script to join multiple files

I am a new to Linux and try to write a script to join three multiple files. For example, there are three files file1 # comment a Kevin b Vin c Sam file 2 # comment a 10 b 20 c 40 file 3 # comment a blue b yellow (7 Replies)
Discussion started by: bonosungho
7 Replies

9. Shell Programming and Scripting

How to store contents of a command in array of variables in shell script?

I want to store contents of command dir in array of variables For eg: dir contents are command d2 demovi~ file inven java new untitled folder d1 demovi er1 filename inven~ myfiles ubuntu desktop xmms ----------------------------------- I... (3 Replies)
Discussion started by: netresearch
3 Replies

10. Shell Programming and Scripting

How to store query multiple result in shell script variable(Array)

:) Suppose,I have one table A. Table A have one column. Table A have 10 rows. I want this 10 rows store into shell script variable. like #!/bin/ksh v_shell_var=Hi here in call oracle , through loop How can I store table A's 10 rows into v_shell_var (Shell Script Array). Regards, Div (4 Replies)
Discussion started by: div_Neev
4 Replies
Login or Register to Ask a Question