LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2012, 01:18 AM   #1
Sharath Ravi
Member
 
Registered: Jun 2012
Posts: 37

Rep: Reputation: Disabled
Shell scritpting


hi,

i am very much new to linux

I have file with line with .sql names in it

Like

Animations/lang/.svn/tmp/text-base/
Animations/lang/English/.svn/
Animations/lang/English/.svn/prop-base/
Animations/lang/English/.svn/props/
Animations/lang/English/.svn/text-base/
Animations/lang/English/.svn/tmp/
Animations/lang/English/.svn/tmp/prop-base/
Animations/lang/English/.svn/tmp/props/
Animations/lang/English/.svn/tmp/text-base/

Need a script to remove .svn in those lines

can any1 help me please....
 
Old 06-21-2012, 01:39 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
A simple sed should do the job

Code:
sed 's/\/.svn\//\//g'  input.sql > output.sql
Quote:
Originally Posted by Sharath Ravi View Post
hi,

i am very much new to linux

I have file with line with .sql names in it

Like

Animations/lang/.svn/tmp/text-base/
Animations/lang/English/.svn/
Animations/lang/English/.svn/prop-base/
Animations/lang/English/.svn/props/
Animations/lang/English/.svn/text-base/
Animations/lang/English/.svn/tmp/
Animations/lang/English/.svn/tmp/prop-base/
Animations/lang/English/.svn/tmp/props/
Animations/lang/English/.svn/tmp/text-base/

Need a script to remove .svn in those lines

can any1 help me please....
 
Old 06-21-2012, 02:18 AM   #3
Sharath Ravi
Member
 
Registered: Jun 2012
Posts: 37

Original Poster
Rep: Reputation: Disabled
thanks for the reply

need to delete that line it self ie the line which contains .sql. There are so many lines in this page.



Quote:
Originally Posted by rosehosting.com View Post
A simple sed should do the job

Code:
sed 's/\/.svn\//\//g'  input.sql > output.sql
 
Old 06-21-2012, 02:29 AM   #4
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
I'm not sure if I understand you right.

To delete all lines containing ".svn":

Code:
sed '/\/.svn\//d' input.sql > output.sql

Quote:
Originally Posted by Sharath Ravi View Post
thanks for the reply

need to delete that line it self ie the line which contains .sql. There are so many lines in this page.
 
Old 06-21-2012, 10:21 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
A few points to add to the above about using sed.

1) You can avoid having to escape any "/"s in the expression by using a different delimiter. For the "s" command, you can simply use a different character. For the range entries, you can use a different character if you precede the first one with a backslash. Any basic ascii character except null or newline can be used.

2) On the other hand, sed treats the expressions as regular expressions, and certain characters in those are special, such as the period. To match a literal "." then, you need to escape it, or as I prefer, box it in a bracket expression.

3) You can edit the original file directly if you use the -i option, at least with gnu sed.

Code:
sed -i 's^/[.]svn^^' inputfile	#remove substrings from lines (delimiter is "^")

sed -i '\@/[.]svn@d' inputfile	#remove entire lines matching a substring (delimiter is "@")
Here are a few useful sed references:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt


You might also consider using ed instead. It's a dedicated text editor and can manipulate files directly. The syntax is similar to sed, but its delimiters are more primitive and only accept the backslash.

Code:
printf '%s\n' '% s/[/][.]svn//' 'w' | ed -s inputfile

printf '%s\n' 'g/[/][.]svn/d' 'w' | ed -s inputfile
How to use ed:
http://wiki.bash-hackers.org/howto/edit-ed
http://snap.nlc.dcccd.edu/learn/nlc/ed.html
(also read the info page)

Last edited by David the H.; 06-21-2012 at 10:23 AM.
 
Old 06-21-2012, 10:45 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,592

Rep: Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520Reputation: 7520
not to speak about grep: grep -Fv .svn inputfile > outputfile
 
Old 06-22-2012, 01:10 AM   #7
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Or awk,

Code:
awk '$0 !~ /\.svn/ {print $0}' inputfile > outputfile
 
Old 06-22-2012, 01:16 AM   #8
Sharath Ravi
Member
 
Registered: Jun 2012
Posts: 37

Original Poster
Rep: Reputation: Disabled
Talking

Thanks every1 it worked.......
 
  


Reply


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
LXer: Webian Shell: Prototype Web-Based Shell LXer Syndicated Linux News 0 07-05-2011 10:00 AM
[SOLVED] Needed to be $HOME/.bashrc disabled when user shell is 'rbash' (restricted shell) mgumbau Linux - General 2 06-16-2011 06:17 AM
How to run root privileged Linux command as normal user via shell shell tcegrid Linux - Newbie 1 06-23-2008 03:38 PM
LXer: Shell tip: Set the shell prompt and themes in Linux Terminal LXer Syndicated Linux News 0 06-12-2007 03:02 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 09:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:26 PM.

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