remove particular line from a file using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove particular line from a file using sed
# 1  
Old 08-29-2012
remove particular line from a file using sed

Hi

i need to remove all the lines staring with 'printf("\n' from a file,

example : the file tmp.txt contains

Code:
 
printf("\n ");
printf("\n good");
  printf("\n ");
    printf("\n ");
printf("");
printf(
m_sprintf(for
printf("\n ");

i have tried with following commands but its not working, pls help.

Code:
 
sed '/^* printf/d' t
sed '/^. printf/d' t

# 2  
Old 08-29-2012
Does this meet your requirement?
Code:
sed '/^[[:blank:]]*printf("\\n/d' infile

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-29-2012
Code:
sed '/^ *printf/d' t

# 4  
Old 08-29-2012
Quote:
Originally Posted by elixir_sinari
Does this meet your requirement?
Code:
sed '/^[[:blank:]]*printf("\\n/d' infile

this command meet the requirement, could you explain the details of this command.
# 5  
Old 08-29-2012
^ -- beginning of line
[[:blank:]]* -- 0 or more occurrences of the blank character class (which matches a space or a tab).
printf("\\n -- your pattern. The \n has to be given as \\n. Otherwise, the sed regexp parser will "eat" the backslash before n and treat it as a literal n
# 6  
Old 08-29-2012
Quote:
Originally Posted by mprakasheee
this command meet the requirement, could you explain the details of this command.

[:blank:]Space and TAB characters only.[:blank:]* --> match Space or TAB characters
\\n ---> escape the back slash by adding one more \ ( back slash)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove tab space and new line from a file using sed?

i am using the default sed package that comes with solaris. (11 Replies)
Discussion started by: chidori
11 Replies

2. UNIX for Dummies Questions & Answers

Sed to remove only first line erroneously removes last line too

Hello everyone, This is my first posting. I have read the rules of this forum. I have searched many various threads and haven't found one that applies to my situation or suggestions to fix the issue. I do appreciate the help. I am trying to execute a basic UNIX script in a Solaris... (4 Replies)
Discussion started by: dqrgk0
4 Replies

3. Shell Programming and Scripting

SED to remove a line above and lines below.

:confused:Hi All, I need help on removing lines in a text file. Sample file : When there is a match ip for IPAddress in my `cat ip.out`, proceed delete line above until string "Comp" is found. Thank you very much. ---------- Post updated at 12:56 AM ---------- Previous update was... (4 Replies)
Discussion started by: chiewming
4 Replies

4. Shell Programming and Scripting

sed -e remove line from file

Hi Trying to remove line from file log_January_1_array and code below doesn't work. $(sed -e '/"$n"/d' <log_January_1_array >log_January_1_array_1) sed doesn't know what is in $n variable and nth happens. Please advice how to make sed running this. thx (2 Replies)
Discussion started by: presul
2 Replies

5. Shell Programming and Scripting

sed: remove first character from particular line

Hello Experts, I have a file "tt.txt" which is like: #a1=a2 b1=b2 #c1=c2 I need to remove the pound (#) sign from a particular line. In this case let us assume it's 3rd line : "#c1=c2" I can do it through: sed "s/#c1=c2/c1=c2/" tt.txtbut it is possible that I may not know the value... (6 Replies)
Discussion started by: hkansal
6 Replies

6. Shell Programming and Scripting

sed to remove 1st two characters every line of text file

what is the sed command to remove the first two characters of every line of a text file? each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though. for example, >cat file1.txt 10081551 10081599 10082234 10082259 20081134... (20 Replies)
Discussion started by: ajp7701
20 Replies

7. Shell Programming and Scripting

Remove blank line - SED

HI, I have this list of apps like so: DivX Products.app DivX Support.app Uninstall DivX for Mac.app Build Applet.app SpringBoard.app Interface.app MobileAddressBook.app MobileSafari.app MobileSlideShow.app Preferences.app Install Flash Player 8 OSX.app Yap.app check_afp.app ... (10 Replies)
Discussion started by: pcwiz
10 Replies

8. Shell Programming and Scripting

sed remove last 10 characters of a line start from 3rd line

hello experts, I need a sed command that remove last 10 characters of a line start from 3rd line. any suggestions? Thanks you (7 Replies)
Discussion started by: minifish
7 Replies

9. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies
Login or Register to Ask a Question