Sponsored Content
Top Forums Shell Programming and Scripting sed will not write to same file Post 302816473 by Don Cragun on Tuesday 4th of June 2013 04:03:37 AM
Old 06-04-2013
Quote:
Originally Posted by rveri
Hi bbaumg02,

Here you go, with classic ed,

Code:
ls --sort=extension > directory.txt
echo "Enter you user name..."
read input
printf "1i\n$input\n.\nw\nq" | ed -s directory.txt

date=`date`
printf "2i\n$date\n.\nw\nq" | ed -s directory.txt
echo "The operation completed successfully."


ed works where sed won't
Enjoy , Have fun!.

---------- Post updated 06-04-13 at 03:44 AM ---------- Previous update was 06-03-13 at 11:06 PM ----------

bbaumg02,
Here how it ll look like:

Code:
$./script
Enter you user name...
JOHN
The operation completed successfully.

Code:
$ ls -lrt
total 20
-rwxrwxr-x 1 adms adms 236 Jun  4 00:39 script
-rw-rw-r-- 1 adms adms  98 Jun  4 00:39 test1
-rw-rw-r-- 1 adms adms 144 Jun  4 00:39 test3
-rw-rw-r-- 1 adms adms 144 Jun  4 00:39 test2
-rw-rw-r-- 1 adms adms   0 Jun  4 00:40 unix.com
-rw-rw-r-- 1 adms adms  79 Jun  4 00:40 directory.txt
$
$ cat directory.txt
JOHN
Tue Jun  4 00:40:42 PDT 2013
script
test1
test2
test3
unix.com
directory.txt
$

Hope this is what you were looking for.
Hi rveri,
If that is what is wanted, why make it so complex? Why not just use something like:
Code:
printf "Enter you user name: "
read input
{      echo "$input"
       date
       ls --sort=extension
} > directory.txt
[ $? -eq 0 ] && echo "The operation completed successfully."

I don't see the need for ed or sed if this is the desired output.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to read and write to very same file

This is likely to be a dumb one. How can I use sed to substitute string occurances having it read from an input file and write to this very same file ? I have a file with lots of occurances of '2006', I want to change it to '2007', but I'd like these changes to be saved on the input file. ... (5 Replies)
Discussion started by: 435 Gavea
5 Replies

2. Shell Programming and Scripting

How To Write Sed Function

hi iam facing problem regarding sed function. give me reply with example of sed function. and what to meanings of $# and @ in scripting please as reply as soon as possible (1 Reply)
Discussion started by: naveeng.81
1 Replies

3. Shell Programming and Scripting

SED command for read and write to different files

Hi I need some help on SED command I am writing a shell script which does the following: 1. Read one line at a time from a file abc.txt which has millions of lines 2. Prefix each line read with some text " 3. Post fix each line read with a quote " 4. Write the new modified... (11 Replies)
Discussion started by: gaurav_1711
11 Replies

4. UNIX for Dummies Questions & Answers

using sed to write horizontally & sequentially in a file

Hey there I have two commands to get exactly the data i want but.. i want to write them into a file side by side and in the same order so that they always match. So what i'm hoping to learn from this thread is some of the different ways one could take the output of grepped data and write them in... (7 Replies)
Discussion started by: phpfreak
7 Replies

5. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

6. Shell Programming and Scripting

sed - write remaining input and quit?

I'm an infrequent user of sed. I searched this and other forums and read quite a bit of the O'Reilly book for an answer without luck. In my script I want sed to write the remainder of the input file and quit if it matches a pattern. e.g /Google/ Does anyone have an answer? thank. (5 Replies)
Discussion started by: lyledp
5 Replies

7. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

8. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

9. UNIX for Advanced & Expert Users

Sed: couldn't write 1378 items to stdout: No space left on device

Hi , In file first line start with "",when trying to remove using sed i am getting the below error .Please advise sed -e 's///g' -e 's/$]//g' segment1.txt >>segment_m1 sed: couldn't write 1378 items to stdout: No space left on device Thanks, Mohan (1 Reply)
Discussion started by: mohan705
1 Replies

10. UNIX for Beginners Questions & Answers

How to write a space with sed?

Hi, I wish insert a line into a file, I created it with : #-------------------------------------------------------------- # The loopback network interface #-------------------------------------------------------------- auto lo iface lo inet loopback ... (7 Replies)
Discussion started by: Arnaudh78
7 Replies
All times are GMT -4. The time now is 10:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy