How to delete a particular text without opening the file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete a particular text without opening the file.
# 8  
Old 08-29-2005
And here are the tutorials. One is from this forum itself

Check out the tutorial page.

The other is the Orielly Book sed and awk

vino
# 9  
Old 02-21-2008
hi.. need help removing some values

I need to remove the lines for which the values after the second ":" are null or consists of only spaces.
Ex:

a:a:
b:B:BB
c:C:CC
d:d:


Here the first and the fourth line can contain space.
How to get the following output?
b:B:BB
c:C:CC
# 10  
Old 02-21-2008
Code:
sed -n -e "s/^[^:]*:[^:]*:[^ ]*/&/p" in.txt

# 11  
Old 02-21-2008
Thanks vino, but this is giving all the lines as the output.
To clarify the part AFTER the second colon can contain spaces.

I am new to Unix so can't actually decode the RegEx for the sed. Smilie
Can you please modify it as needed. Thanks
# 12  
Old 02-21-2008
one way i found to do it is using AWK:
awk -F: '{if($3!="" && $3!=" " && $3!=" " && $3!=" " && $3!=" " && $3!=" " && $3!=" "){print}}' log.log
but this does not seem like a feasible solution since the number of spaces is fixed.
# 13  
Old 02-21-2008
Quote:
Originally Posted by stevefox
Thanks Vino,

I have another question.

Could someone tell me how to delete a string from a line in a specific position using sed or other editors which doesn't require files to be opened?

e.g. I have a file called myfile.txt which contains three lines of text below and I want all of the lines to have 5 characters or less.

1234567
a b c d e
098


I want the result to be like below:

12345
a b c
098

Any help will be appreciated.

BTW please let me know if you have any recommended sites for learning unix commands such as above.

Cheers
Steve
Use cut command to get the 5 characters
Quote:
cut -c 1-5 file1 > file2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete records based on a text file from a text file

Hi Folks, I am a novice and need to build a script in bash. I have 2 text files data.txt file is big file, column 2 is the we need to search and delete in the output. The filter file contains the rows to be deleted. Data.txt state city zone Alabama Huntsville 4 California SanDiego 3... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. UNIX for Dummies Questions & Answers

How to read a file without opening the file and delete last line?

I have file called "text". The contents are as below : aaa bbb ccc ddd eee ffff ddd hhhh iiii I want to read this file without opening and and delete the last line. How can it be done? (4 Replies)
Discussion started by: the_hunter
4 Replies

3. UNIX for Dummies Questions & Answers

^H characters appear when opening text file using vi - RHEL

Version Info: $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.8 (Tikanga) $ $ uname -a Linux stryker138 2.6.18-308.13.1.el5 #1 SMP Thu Jul 26 05:45:09 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux I redirected manpage of ksh command's output to a text file as shown... (6 Replies)
Discussion started by: kraljic
6 Replies

4. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

5. Shell Programming and Scripting

Delete block of text in one file based on list in another file

Hi all I currently use the following in shell. #!/bin/sh while read LINE do perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile" done < "listfile" NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it... (3 Replies)
Discussion started by: Festus Hagen
3 Replies

6. Web Development

opening text files with javascript

Im aware under IE, javascript uses ActiveX Objects to open up and manipulate text files, excel files etc.. How abouts would I open a text file using javascript in Firefox ? thanks (1 Reply)
Discussion started by: JamesGoh
1 Replies

7. Shell Programming and Scripting

How to Delete string without opening a file

Hi Experts, I have several big size file arround 900 MB. From the file I need to delete some common strings but without opening the file. here is example- in file <?xml version='1.0' encoding='ISO-8859-1' standalone='no'?> <LogItems> <log logid="8423b5ae190810252359350480/1/1/1"> ... (6 Replies)
Discussion started by: thepurple
6 Replies

8. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

9. UNIX for Dummies Questions & Answers

delete file without opening vi

hi there guys, wonder if any gurus can help me out on this one... try searching the past threads but cant find anything. i have this huge file but when i use vi to open it it gives me the following error: <"pmrepserver.txt""/var/tmp/Ex86200" There is not enough space in the file... (7 Replies)
Discussion started by: lweegp
7 Replies

10. Shell Programming and Scripting

how to delete away text in a file?

I have this xml file which is call p.txt and it contains the follwing: 16:13:56 Msg send to Queue=<pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <system_c>HPREGATE</system_c> <trans_c>HSPG</trans_c> <trans_dt>20060105161333</trans_dt> <user_id_m></user_id_m> ... (5 Replies)
Discussion started by: forevercalz
5 Replies
Login or Register to Ask a Question