LinuxQuestions.org
Review your favorite Linux distribution.
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-15-2003, 02:18 PM   #1
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
inserting text into a file


Howdy,

This is what I am looking at

sed /$expression/a\ "$comment" $fname > $fname.cmt

no problem with it except that i want to edit the file $fname itself

the problem is $fname is being written with

cat /dev/ttyUSB0 >> $fname

I would like to be able to actually insert the comment into $fname without causing a problem with the file as it is being written.

sed /$expression/a\ "$comment" $fname > $fname

results in an empty file


may I need to use echo or something

thanks,
 
Old 08-15-2003, 02:28 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Re: inserting text into a file

I think I have doen something similar before and I had to use echo - eg:
echo `sed /$expression/a\ "$comment" $fname` > $fname
 
Old 08-15-2003, 03:21 PM   #3
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
It seems to work, except that the line is inserted without a new line at the end

~090 File Number:9030, Shot Number:2977, Shot Point Line:562 , Station:123
Observers comment: Hello ~090 Mag Tape Usage: MT2U0-raw

I have not checked to see what is happening to the cat process yet.
 
Old 08-15-2003, 03:39 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
What am I thinking - when I was doing something similar it was with a different script (perl search and replace type script). With sed you can just use the -i switch.
sed -i /$expression/a\ "$comment" $fname
 
Old 08-15-2003, 04:45 PM   #5
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
that's it

hard to believe it was that simple

learning sed is fun
 
Old 08-15-2003, 04:53 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Yeah - the funy thing was the first time I really used it was for modifying shadow password files - just as well I made backups first
 
  


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
Shortcut keys for inserting text/code in Linux Horos23 Programming 1 02-03-2005 03:50 PM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
Gimp-1.3 inserting text nadine.mauch Linux - Software 0 07-26-2004 03:07 AM
inserting/deleting characters into a text file ananthbv Programming 7 07-13-2004 11:40 PM
Inserting Text wildcat22 Linux - General 8 04-25-2004 07:51 AM

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

All times are GMT -5. The time now is 08:38 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
Open Source Consulting | Domain Registration