Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-07-2014, 04:42 PM   #1
LQ Newbie
Registered: May 2014
Posts: 2

Rep: Reputation: Disabled
Modifying text/file names and recording changed line with sed


I have a project that I am working on that requires me to manipulate text with sed. I've figure most of the problem out except for the requirement to write the line to be change to a unique corr file for each one of the 10 files in the directory. The unique files are created but there is not text in them. My assumption is that the last command opens the file as blank and doesn't have changes to make. thus the blank file.

for i in project*;do
sed -n -e /CS261/CMPTR261/p' $i > corr_$f;
sed -i 's/CS261/CMPTR261/g' $i;
sed -n -e '/UNIX/LINUX/p' $i > corr_$f;
sed -i 's/UNIX/LINUX/g' $i;
sed -n -e /Project/Assignment/p' $i > corr_$f;
sed -i 's/Project/Assignment/g' $i;
sed -n -e /project/assignment/p' $i > corr_$f;
sed -i 's/project/assignment/g' $i;
sed -n -e /PROJECT/ASSIGNMENT/p' $i > corr_$f;
sed -i 's/PROJECT/ASSIGNMENT/g' $i;
mv $i ${i/project/assign}; done;
Old 06-07-2014, 09:49 PM   #2
Senior Member
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,539

Rep: Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419Reputation: 1419
When posting code, please put the code between [code][/code] tags as it aids readability.

I suggest that you pay more attention to quoting. e.g.
sed -n -e /CS261/CMPTR261/p' $i > corr_$f;
should be
sed -n -e '/CS261/CMPTR261/p' $i > corr_$f;
Also you have used the '>' redirection. This will overwrite any existing file with the same name.
Use the '>>' redirection instead, so that if the file does not exist, it is created. Or, if it does exist, then the output is appended.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Modifying text file with "one command line" SED command... daleo Linux - Newbie 3 01-13-2012 05:32 AM
sed command to replace line in text file gengwei89 Linux - Newbie 6 11-06-2011 08:10 AM
[SOLVED] trying to insert text in the last line of a file with sed command.... Sayan Acharjee Linux - General 7 10-04-2010 05:00 AM
using sed to replace text on one line in a text file vo1pwf Linux - Newbie 5 06-24-2009 07:54 AM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM

All times are GMT -5. The time now is 10:19 AM.

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