LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Greeting,

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
f=${i:7:9}
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, 10:49 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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.
Code:
sed -n -e /CS261/CMPTR261/p' $i > corr_$f;
should be
Code:
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.
 
  


Reply


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 06:32 AM
sed command to replace line in text file gengwei89 Linux - Newbie 6 11-06-2011 09: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 06:00 AM
using sed to replace text on one line in a text file vo1pwf Linux - Newbie 5 06-24-2009 08:54 AM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 05:32 PM


All times are GMT -5. The time now is 08:06 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration