Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-26-2007, 09:29 AM   #16
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244

you should start a new thread.
Old 09-02-2010, 10:24 AM   #17
LQ Newbie
Registered: Sep 2010
Posts: 1

Rep: Reputation: 0
Smile Shell command to replace a string

Originally Posted by Anant Khaitan View Post
Guys please tell me how do I delete a particular string.. Like for
echo | <additional command>
should return only
i.e delete everything after the dot..
Is it possible with tr
This will replace all occurrences of '.abc' with null.
echo | sed 's/.abc//g'
Old 09-22-2010, 01:07 AM   #18
LQ Newbie
Registered: Sep 2010
Posts: 18

Rep: Reputation: 0
Smile pattern match answer

Hi pal,
for do my work, where I need to work all files in a folder(which are .js or .html or .php extension only), I work a script like this,
here my pattern is "123". Which delete a line which encounter a "123"
any where in line , the script is:

grep -rl --include=*.{php,js,html} 123 $1 | xargs sed -i".bckp" '/123/d'
rm -f $1/*.bckp
#echo $1
#echo $2

Wish this may help you
Anes P.A
Old 10-15-2010, 05:33 AM   #19
LQ Newbie
Registered: Oct 2010
Posts: 9

Rep: Reputation: 0
1. option
echo | cut -d"." -f1
basename .abc
echo ${x%.*}
echo ${x/.*/}
echo $x | perl -pe 's/\..*$//;s{^.*/}{}'

So there you have something to work with.
Old 06-25-2011, 11:21 AM   #20
LQ Newbie
Registered: Jun 2011
Posts: 6

Rep: Reputation: Disabled
Smile Similar problem

I am having similar problem.
I need to replace
username1 with #username1
username2 with #username2
and so on
in 800 different text files in different directories.
Old 06-25-2011, 02:09 PM   #21
Senior Member
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello Lucifer999, welcome to LQ,

please open your own thread for this question. This one is quite old and most of the posters are no longer active here in the forums.

Old 06-26-2011, 01:42 AM   #22
LQ Newbie
Registered: Jun 2011
Posts: 6

Rep: Reputation: Disabled
Thank you for the suggestion.....
Old 08-23-2011, 04:58 AM   #23
Registered: Aug 2011
Distribution: Linux Mint
Posts: 103

Rep: Reputation: Disabled
another awk

Originally Posted by jkobrien View Post
awk 'match($0,"") == 0 {print $0}' FILENAME > NEWFILENAME

Here is another version:
awk '$0 !~ / {print}' FILENAME > NEWFILENAME
In fact it is the same as yours. I found all awk programming share same logic, isn't it? But awk always looks not simple enough, a bit heavy. Can it be easier as Sed?

Last edited by cristalp; 09-14-2011 at 06:28 AM.


awk, delete, file, line, sed, string

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
Procmail: match pattern then pass to shell script essdeeay Linux - Software 1 11-08-2004 02:19 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration