LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2009, 07:34 PM   #1
ZimMonkey
LQ Newbie
 
Registered: Jun 2009
Posts: 13

Rep: Reputation: 0
Altering multiple files at once


I'm trying to figure out how to change multiple files at once. I have 400 or so files that I need to awk out fields 2 and 3, then save the file under the original name, replacing the old file. With one or 2 files that isn't a problem, I would just do it manually. But I'm stuck now that I have to so this for several hundred files. All the file names are numbers (304, 384, 2930). I just can't figure out an easy way to do this. Any suggestions?

Thanks

Zim
 
Old 08-16-2009, 08:06 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Assuming all the files are in the same directory:

Code:
cd the_directory_where_the_files_are
for filename in *; do
   cp $filename $filename.bak
   ((awk stuff)) > temp
   mv temp $filename
done
Replace ((awk stuff)) with whatever you are using on individual files
 
Old 08-17-2009, 02:05 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just using awk:
Code:
awk '{print $2, $3 > "../ouput/"FILENAME}' *
This put the output files in the directory ../ouput. Then you can simply replace the original ones.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding multiple files with ascending numerical files extensions unim21 Linux - Newbie 3 04-23-2009 07:50 PM
copying multiple files in multiple folders ?? stratotak Linux - Newbie 2 02-21-2009 09:41 AM
cp multiple files to multiple directories Heksie Linux - Newbie 2 02-05-2009 05:17 AM
Change text in multiple files in multiple directories vivo2341 Linux - General 5 11-27-2006 08:16 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration