LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-26-2007, 09:29 AM   #16
ghostdog74
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
mvona
LQ Newbie
 
Registered: Sep 2010
Posts: 1

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

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

#!/bin/bash
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
Regards
Anes P.A
 
Old 10-15-2010, 05:33 AM   #19
kontrabant
LQ Newbie
 
Registered: Oct 2010
Posts: 9

Rep: Reputation: 0
1. option
echo abcdef.abc | cut -d"." -f1
2.option
basename abcdef.abc .abc
3.option

x=abcdef.abc
echo ${x%.*}
echo ${x/.*/}
4.option
x=abcdef.abc
echo $x | perl -pe 's/\..*$//;s{^.*/}{}'


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

Rep: Reputation: Disabled
Smile Similar problem

Hi,
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
markush
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.

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

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

Rep: Reputation: Disabled
another awk

Quote:
Originally Posted by jkobrien View Post
awk 'match($0,"username@email.com") == 0 {print $0}' FILENAME > NEWFILENAME

John
Here is another version:
Code:
awk '$0 !~ /username@email.com/ {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.
 
  


Reply

Tags
awk, delete, file, line, sed, string



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:25 AM.

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