Visit Our UNIX and Linux User Community


Easy ex editor command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Easy ex editor command
# 1  
Old 07-23-2009
Easy ex editor command

I've this command in a script which edits the file ...

bash$ cat temp_file.txt
THREAD #2 2 Running
bash$ (echo "s/THREAD #2/d"; echo 'wq') | ex -s temp_file.txt
bash$ cat temp_file.txt
THREAD #2 2 Running



If i've more than 1 line it easily deletes the line, but if it is the last line left in the file it simply does not delete>?

not able to figure out ... please help
# 2  
Old 07-23-2009
Assuming this is vim... you need to do something like:

Code:
(echo '%g/THREAD #2/d'; echo 'wq') | ex -s temp_file.txt

# 3  
Old 07-23-2009
Code:
This line quoted actually changes the string to a character "d" rather than deleting the line.

(echo "s/THREAD #2/d"; echo 'wq') | ex -s temp_file.txt

This will actually delete the line containing the first occurance of the string.

(echo "/THREAD #2/d"; echo 'wq') | ex -s temp_file.txt

However if another process has the file open (check with "fuser") then the edit could be failing.
# 4  
Old 07-23-2009
my bad ...

it was (echo "g/THREAD #2/d"; echo 'wq') | ex -s temp_file.txt

cjcox ... I tired adding % in front of g it would not work...

methyl...Your poposal also does not delete the line if its the finst and only line in the file

Thanks to both of you for replying .... Please feel free to try on ur terminal as it is only one line file and one command ...

Previous Thread | Next Thread
Test Your Knowledge in Computers #682
Difficulty: Easy
Steve Job's was the primary founder and majority shareholder of Pixar
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with regular command creation for editor vi

Hi, I need help. I need to build command for line command editor vi. I want to take the whole string and assemble it in a regular expression. He then folded into another shape. Can anyone help me? (4 Replies)
Discussion started by: Pabloss
4 Replies

2. UNIX for Beginners Questions & Answers

Accessing Isql command via VI editor

Hi Guru's, I'm new at Unix. I am tasked to monitor the filesystem utilization on OS level (Unix) and DB (Sybase) for multiple systems. I am thinking to use vi editor and make a file, execute that file and all the file systems I need to monitor will be be shown. My script inside vi goes in... (8 Replies)
Discussion started by: Xworks
8 Replies

3. UNIX for Dummies Questions & Answers

Command to quit from vi editor

Hi Folks I have opened a log file in Vi editor vi abc.logPlease advise me how to finally quit from Vi editor, which command is there..! Is it :q<Enter> (1 Reply)
Discussion started by: KAREENA18
1 Replies

4. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

5. UNIX for Dummies Questions & Answers

Search command on vi editor

Hi all, Here is an example, I would wan to search for all string consists of IMP but not IMP-00015. Values other than 00015 is fine, is there anyone knows how to do that? Thanks. (2 Replies)
Discussion started by: *Jess*
2 Replies

6. HP-UX

Easy one : command listing total memory

Hi, I have been searching for a command that lists the total amount of memory in the HP-UX doc but haven't found it yet. vmstat is not exactly what i want. Does the command exists on HP UX? :confused: :confused: :confused: :confused: :confused: (4 Replies)
Discussion started by: beginer
4 Replies

7. UNIX for Dummies Questions & Answers

Easy question.. from a df -k command 205181344 = 200 gigs, right?

See topic. I always have problems with the easy conversions. bash-2.03$ df -k . Filesystem kbytes used avail capacity Mounted on /dev/vx/dsk/webtrend/webtrends2 364904448 205181344 158481976 57% /webtrends/production/wtm_wtx/datfiles pretty... (4 Replies)
Discussion started by: LordJezo
4 Replies

8. UNIX for Dummies Questions & Answers

vim as command line editor

Here is my problem, I manage a SunOs 5.8 Server, vi is the default command line editor, I have a line on each users .kshrc profile as follows: export EDITOR=/bin/vi I want to use vim as the command line editor, the below line doesn't work export EDITOR=/bin/vim Thank you (1 Reply)
Discussion started by: tony3101
1 Replies

9. UNIX for Dummies Questions & Answers

editor command

I want to copy lines say from 2-5 to line after 20 in vi editor. Can I achieve this in a single command in vi editor. Thanks. (2 Replies)
Discussion started by: tselvanin
2 Replies

10. UNIX for Dummies Questions & Answers

vi editor - ex Command help

:1,10 s/yes/no/g this ex command will substitute yes with no everytime it is found within the first 10 lines of the file. :s/yes/no/g this ex command will substitute yes with no everytime it is found for the line where the cursor is on my question is how could this substitution be... (4 Replies)
Discussion started by: theDirtiest
4 Replies

Featured Tech Videos