Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Script to find and remove characters

Shell Programming and Scripting


Tags
linux

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-29-2008   -   Original Discussion by Zerby
Zerby Zerby is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 29 January 2008, 6:03 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Script to find and remove characters

Hi.

I have many files in a folder, and even more in the subfolders. I need a script that finds and removes certain characters (them being /n in this one) in the files in the folder and it's subfolders.

So, could someone write me a script that works in Linux, does this:

Searchs for "/n" in all files in the folder and it's subfolders.
Removes the "/n" from all the files

Thank you VERY much, I'm really a newbie in these things and I need this badly.
Sponsored Links
    #2  
Old Unix and Linux 01-29-2008   -   Original Discussion by Zerby
KevinADC KevinADC is offline Forum Advisor  
Registered User
 
Join Date: Jan 2008
Last Activity: 11 September 2009, 3:44 PM EDT
Posts: 729
Thanks: 0
Thanked 0 Times in 0 Posts
You may be new, but what have you tried so far?
Sponsored Links
    #3  
Old Unix and Linux 01-29-2008   -   Original Discussion by Zerby
Zerby Zerby is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 29 January 2008, 6:03 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I've been trying to google, and find the code from this forum. But, I have to say, I don't really know anything about this kind of coding, so:

I haven't really tried nothing.

I just got this task, as I'm in work atm, with "nothing better to do".

As said, if you can write me such code, I would appreciate it very much.
    #4  
Old Unix and Linux 01-29-2008   -   Original Discussion by Zerby
pt14 pt14 is offline
Registered User
 
Join Date: Nov 2005
Last Activity: 18 June 2011, 5:29 PM EDT
Posts: 31
Thanks: 2
Thanked 0 Times in 0 Posts
for i in `find . -type f`
do
cat $i|tr -d '\n' > newfile
mv newfile $i
done
Sponsored Links
    #5  
Old Unix and Linux 01-29-2008   -   Original Discussion by Zerby
KevinADC KevinADC is offline Forum Advisor  
Registered User
 
Join Date: Jan 2008
Last Activity: 11 September 2009, 3:44 PM EDT
Posts: 729
Thanks: 0
Thanked 0 Times in 0 Posts
I don't write code for people, I prefer to help them with their code, but there are many others here that will write the code for you, as pt14 has done.
Sponsored Links
    #6  
Old Unix and Linux 01-30-2008   -   Original Discussion by Zerby
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
Quote:
Originally Posted by pt14 View Post
for i in `find . -type f`
do
cat $i|tr -d '\n' > newfile
mv newfile $i
done
beware of files with spaces. put quotes around `find....`
Also, quote your variables and forget about the cat.

Code:
...
tr -d "\n" < "$i" > newfile
...

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find & remove characters in filenames barrydocks UNIX for Dummies Questions & Answers 19 12-22-2011 05:05 AM
Want to remove the last characters from each row of csv using shell script rajak.net Shell Programming and Scripting 24 12-15-2011 05:54 AM
shell script to find noof characters in a file name krishnampkkm UNIX for Dummies Questions & Answers 10 03-10-2010 03:24 AM
How to remove Ctlr-M characters from file from a unix script akashtcs Shell Programming and Scripting 2 08-18-2009 05:11 AM
sed script to remove nth characters from end of filename Monkey Dean Shell Programming and Scripting 2 06-24-2009 02:39 AM



All times are GMT -4. The time now is 01:41 AM.