Sponsored Content
Top Forums Shell Programming and Scripting Reading contents of files from a directory Post 302890050 by chacko193 on Tuesday 25th of February 2014 01:06:58 AM
Old 02-25-2014
If you want to display the output on stdout and save it in file as well, you can use the tee command.
Try:
Code:
for file in /path/to/your/directory/*.txt
do
  echo "$file" |  tee -a out_file.txt
  echo "======================================"
  cat $file | tee -a out_file.txt
  echo | tee -a out_file.txt
  mv $file ${file}.old  # change this to rm to remove the file.
done

When you test this script make sure that the correct files are removed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading files in directory

Hi Everyone , have a nice day i need a help on this thing algo is something like in certain path like /root/user1 i have many files , i need a code which could open every file one by one and then each file has contents like this <moid>CcnCounters=CAPv3-Received-Total-Requests, Source =... (3 Replies)
Discussion started by: Dastard
3 Replies

2. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

3. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

4. AIX

reading files from a directory.

Hi all, I have a shell script where it processes a set of files from a particular directory (shared location among 4 servers). i.e. under this directory /shared/work/ I have a set of files that needs to be processed. Since the number of files are alot, I have this script to be run from 4... (2 Replies)
Discussion started by: haroon_a
2 Replies

5. UNIX for Dummies Questions & Answers

Reading files in script from another directory

Hi I'm trying to call my files from different directories in my script. Can you please help me. Here is my script: #!/bin/bash #---------------------------------------------------------------------------------------------------------------------- #This script allows the user... (1 Reply)
Discussion started by: ladyAnne
1 Replies

6. Shell Programming and Scripting

Constructing a string by reading the contents of 2 files

Hi all - I am trying to write a script to generate a string that gets sent to an IP phone using wget. This is to upload a phone book of up to 100 entries so the string needs to be constructed in one 'hit'. I am a relative newbie to shell scripts but willing to try anything! I have 2 files: ... (3 Replies)
Discussion started by: cakerack
3 Replies

7. Shell Programming and Scripting

reading files from a directory.

Can some body help me to code this? go to a specific directory.(/home/abcd/test) file1.txt, file2.txt, ... .. filen.txt read the files in side the folder 'test' and print the content of each file into other folder in the same directory lets say(testresult) with the same file name... (4 Replies)
Discussion started by: rocking77
4 Replies

8. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

9. Shell Programming and Scripting

Need Help with Bash - comparing directory contents with list of files

Hey guys, need help with a script I'm trying to write. Basically I need to compare the contents of a folder called "profiles" with a list of files called "template". when the file matches the contents of the folder it needs to set a variable called "checked" to "1" Cookies to anyone... (4 Replies)
Discussion started by: Scriporium
4 Replies

10. 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
INOTICOMING(1)							    INOTICOMING 						    INOTICOMING(1)

NAME
inoticoming - trigger actions when files hit an incoming directory SYNOPSIS
inoticoming [ global-options ] directory actions* DESCRIPTION
Inoticoming is a daemon to watch a directory with Linux's inotify framework and trigger actions once files with specific names are placed in there. For example it can be used to wait for .changes files uploaded into a directory and call reprepro to put them into your repository. GLOBAL OPTIONS
--foreground Do not fork, but stay in the foreground and log to stderr. --logfile filename After forking in the background, log to the specified filename instead of syslog. --pid-file filename Write the pid of the running instance into filename. --initialsearch First search the directory for files already existing and process them with the given rules as if they just appeared. If files show up in this inital phase, they may be processed twice, but should never be missed. (Unless they are too many and the inotify queue overflows). ACTIONS
Each action description is an optional list of options for this action (which files to call it for, what directory to change into before executing it, ...), followed by the command and its arguments ended with a single ; as argument. Like: inoticoming --foreground / --regexp ^v echo There appeared {} in the root directory. ; (Note that the before the ; is needed if and only if you calling it from a shell or anything else interpreting the ; on its own). ACTION OPTIONS --prefix string Only trigger this action, if the filename starts with the specified string. --suffix string Only trigger this action, if the filename ends with the specified string. --regexp regular expression Only trigger this action, if the filename matches the specified regular expression. --chdir directory Change into directory before executing the specified commands. (Note that since it is a well-behaved daemon, its working directory is / which will be inherited by all actions). --stdout-to-log Redirect the command's output (stdout) to the logfile. --stderr-to-log Redirect the command's error output (stderr) to the logfile. EXAMPLES
inoticoming --logfile logs/ilog --pid-file pid $INCOMINGDIR --suffix .changes --stderr-to-log reprepro -s -b $REPREPROBASEDIR --waitforlock 1000 processincoming rulename {} ; This will call reprepro for every new .changes file. Note that giving {} as argument to processincoming (which inoticoming will replace with the filename) so that only that .changes file is processed and reprepro will not complain about a possible other yet incomplete .changes file is only available starting with reprepro version 2.2.2. PROBLEMS
There is no handling of queue overflows yet. REPORTING BUGS
Report bugs or wishlist requests to the Debian BTS (e.g. by using reportbug inoticoming under Debian) or directly to <brlink@debian.org>. COPYRIGHT
Copyright (C) 2007 Bernhard R. Link This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. inoticoming 2007-08-18 INOTICOMING(1)
All times are GMT -4. The time now is 09:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy