473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Looking for accessing and editing multiple files in a directory.

1 New Member
#Looking for logic which can modify multiple files in a #directory.Eg /Sumit/Files/ in this there are 3 file #Sam123.12,Sam437.34,Sam676.81.read file one by one and #need only those line which can match pattern like S[1234 #in a file and delete rest lines in file.

Two things are there:
read multiple files one by one automatically.
modify each file with respect to pattern.

thanks in advance
Oct 14 '10 #1
1 1444
ashitpro
542 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2.  
  3. directory="/Sumit/Files"
  4. mkdir output_dir
  5.  
  6. for f in `ls -1 $directory`
  7. do
  8.         sed '/S\[1234/d' "$directory/$f" > "output_dir/$f"
  9. done
  10.  
It should create new directory named output_dir in your current directory. It will contain all modified files.

In sed command specify whatever regex/pattern you want to match, whichever line matches that pattern will not be redirected to new file.
Oct 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
10540
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
1
7154
by: Primo | last post by:
Hello, I am building a data management application with the following processes: Process 1 is a Windows service which uses FileSystemWatcher to monitor a directory. Process 2 opens a file...
17
16084
by: Kerr | last post by:
Hi all, I am sure that this is quite simple but can't find any good examples anywhere. I need a method of copying multiple files from a source directory to a destination directory. The file...
6
5068
by: Steven | last post by:
I have a problem with moving the backup of my database from machine to machine. The size is 17 Gig and my network keeps timing out when I try to ftp it from machine to machine. I have had the...
10
14471
by: Mateusz Rajca | last post by:
Hi! How do I delete multiple files in C#? I would like the specific code. Thanks! Matt
0
3066
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
1
5821
by: toramadevi | last post by:
Hi ALL, I 'm using DevC++ for writing a C source code to create multiple files and folders under a directory.With the help of mkdir command i am able to get a bunch of 40 folders in the current...
6
2395
by: chrisbirk | last post by:
Hi! I want to write an application on windows xp, which iterates n times a model script (exe) and copies every single run the results (multiple files such as text, maps, subfolders,etc) from the...
4
4853
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
1
1700
by: Fluffywolf | last post by:
Hello, In short: I'm constructing a large web-based graphic intensive game, in which I am looking for a solution for users to download the graphics prior to playing the game and the game...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.