LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 02: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, 02:39 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
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, 03: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, 03:29 AM   #4
rosehosting.com
Member
 
Registered: Jun 2012
Posts: 222

Rep: Reputation: 62
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, 11:21 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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 11:23 AM.
 
Old 06-21-2012, 11:45 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
not to speak about grep: grep -Fv .svn inputfile > outputfile
 
Old 06-22-2012, 02:10 AM   #7
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Or awk,

Code:
awk '$0 !~ /\.svn/ {print $0}' inputfile > outputfile
 
Old 06-22-2012, 02: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 11:00 AM
[SOLVED] Needed to be $HOME/.bashrc disabled when user shell is 'rbash' (restricted shell) mgumbau Linux - General 2 06-16-2011 07:17 AM
How to run root privileged Linux command as normal user via shell shell tcegrid Linux - Newbie 1 06-23-2008 04:38 PM
LXer: Shell tip: Set the shell prompt and themes in Linux Terminal LXer Syndicated Linux News 0 06-12-2007 04:02 AM
'sh' shell - Actually calls legacy Bourne shell, or uses system default? Dtsazza Linux - Software 1 10-28-2005 10:20 AM


All times are GMT -5. The time now is 06:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration