edit command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting edit command
# 1  
Old 09-25-2010
edit command

Code:
printf '3d\nw\nq\n' | ed -s file

please explain the above command what the (ed -s file) will do by getting the first input.

Last edited by vbe; 09-30-2010 at 05:11 AM..
# 2  
Old 09-25-2010
Quote:
Originally Posted by thelakbe
printf '3d\nw\nq\n' | ed -s file

please explain the above command what the (ed -s file) will do by getting the first input.
The printf command prints three "ed" commands as shown below:

Code:
$ 
$ printf '3d\nw\nq\n'
3d
w
q
$ 
$ 

"3d" means delete line number 3.
"w" means write to file.
"q" means quit "ed" editor.

These commands are piped to "ed", so it will execute them on the file "file" silently (due to "-s" flag).

A simple test is as follows -

Code:
$ 
$ 
$ cat -n f15
     1    This is line 1
     2    This is line 2
     3    This is line 3
     4    This is line 4
     5    This is line 5
     6    This is line 6
     7    This is line 7
$ 
$ 
$ printf '3d\nw\nq\n' | ed -s f15
$ 
$ cat -n f15
     1    This is line 1
     2    This is line 2
     3    This is line 4
     4    This is line 5
     5    This is line 6
     6    This is line 7
$ 
$ 

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't edit my Crontab

Hi, I m setting up my crontab for the very first time. I m a non-root user and this is linux $ export EDITOR=vi $ crontab -e no crontab for user1 - using an empty one crontab: installing new crontab "/tmp/crontab.uW0JNx":1: bad command errors in crontab file, can't install. Do you want... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. UNIX for Dummies Questions & Answers

Edit $args within a command

Hi, I'm using a while loop for a given command "bowtie2" with several parameters. mkdir clean paste <(ls --quote-name ./qc/sg_*_R1_val_1.fq.gz) <(ls --quote-name ./qc/sg_*_R2_val_2.fq.gz) |sed 's/"./-1 ./' | sed 's/gz"\t/gz\t -2 /' | sed 's/"//g' |\ while read args ; do ... (5 Replies)
Discussion started by: sargotrons
5 Replies

3. Programming

C++ Edit code

Hi guys, I am learning C++ on my own and i wanna redit the code using classes and heritance to revamp the code below. example class for the card attributes -suit , - rank, - face and also class deck to contain shuffle and a class player with the function to setcard and a function handonecard... (1 Reply)
Discussion started by: ment0smintz
1 Replies

4. Shell Programming and Scripting

Plus edit and edit header

Dear Masters, i have a problem with unix script, till now i just know about how to create header. i want to change file below -63395.2 72653.5 -63361.3 72696.0 ... (9 Replies)
Discussion started by: ipatah
9 Replies

5. Shell Programming and Scripting

edit sed command

how can i make this sed command run faster? sed '51000000,51347442!d' file and sed '51347442,$ !d' file File is a 9GB in size. it runs on sunos 5.10 and linux red hat 6 servers and i use bash. (5 Replies)
Discussion started by: SkySmart
5 Replies

6. Shell Programming and Scripting

up down arrow key and edit on command line.

I am using ksh, By doing change in .profile as set -o vi my updown and history does not work. Also I can not edit command line on prompt using vi command. My TERM is vt100. What is wrong here ? Thanks. :cool: (3 Replies)
Discussion started by: ekb
3 Replies

7. Shell Programming and Scripting

sed command to edit fields

Hi, I'm a newbie to sed and I'm having trouble working with sed and fields. Suppose I have a text file with: AAA RFG:$2.10:6:25Oct06 WDD GGTR:$3.50:5:25Oct06 ADDSJ OO:$1.37:3:26Oct07 UGBDN S:$4.73:1:27Oct06 USY ADC:$2.38:20:27Oct06 And I want to substitute field 2 of line 3 with, say,... (3 Replies)
Discussion started by: aloe_vera
3 Replies

8. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies

9. UNIX for Dummies Questions & Answers

Edit Crontab

Hi I am new to Unix and would like some assistance. I need to edit the crontab file so that a script is set to run at 3:00 am each day. When I telnet to the sun server and type crontab -e a black screen appears and I am unable to make any changes. Could you advice on what is needed to... (11 Replies)
Discussion started by: juliet
11 Replies
Login or Register to Ask a Question