Script to find and remove characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to find and remove characters
# 1  
Old 01-29-2008
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.
# 2  
Old 01-29-2008
You may be new, but what have you tried so far?
# 3  
Old 01-29-2008
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 01-29-2008
for i in `find . -type f`
do
cat $i|tr -d '\n' > newfile
mv newfile $i
done
# 5  
Old 01-29-2008
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.
# 6  
Old 01-30-2008
Quote:
Originally Posted by pt14
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
...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling a find/remove within a script

Greetings all, I am calling a remove from within a script that is used for a cleanup process.. It is not working as expected. Here is what I am doing. I have a config file that lists out a directory name, and the options to run Within the config file DIR1="find... (9 Replies)
Discussion started by: jeffs42885
9 Replies

2. Shell Programming and Scripting

Remove first 2 characters and last two characters of each line

here's what im trying to do. i have a file containing lines similar to this: data.txt: 1hsRmRsbHRiSFZNTTA1dlEyMWFkbU5wUW5CSlIyeDFTVU5SYjJOSFRuWmpia0ZuWXpKV2FHTnRU 1lKUnpWMldrZFZaMG95V25oYQpSelEyWTBka2QyRklhSHBrUjA1b1kwUkJkd3BOVXpWM1lVaG5k... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Windows & DOS: Issues & Discussions

Super Simple Script to remove first characters of any png file

Well I searched the net with varying success, but it seems kinda hard to find a one/max 2 lined command to: strip all *.png files in the folder from their first two characters. Any help is appreciated. In DOS commandline of course... (17 Replies)
Discussion started by: pasc
17 Replies

4. UNIX for Dummies Questions & Answers

find & remove characters in filenames

I have a group of files in different directories with characters such as " ? : in the file names. How do I find these files and remove these characters on mass? Thanks (19 Replies)
Discussion started by: barrydocks
19 Replies

5. Shell Programming and Scripting

Want to remove the last characters from each row of csv using shell script

Hi, I've a csv file seperated by '|' from which I'm trying to remove the excess '|' characters more than the existing fields. My CSV looks like as below. HRLOAD|Service|AddChange|EN PERSONID|STATUS|LASTNAME|FIRSTNAME|ITDCLIENTUSERID|ADDRESSLINE1 10000001|ACTIVE|Testazar1|Testore1|20041|||... (24 Replies)
Discussion started by: rajak.net
24 Replies

6. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

7. UNIX for Dummies Questions & Answers

shell script to find noof characters in a file name

hiiii shell script to find noof characters in a file name, when you run ls -l (using awk) I tried with this ls -l > temp awk -F"," '{print $1 " " expr length $9}' temp but it give some other value instead of file name length (error value like , 563,54,55,56....).How to prnint the... (10 Replies)
Discussion started by: krishnampkkm
10 Replies

8. Shell Programming and Scripting

How to remove Ctlr-M characters from file from a unix script

There are 10 files present which have Ctlr-M characters appended to each line of all files. I have a unix script which processes the files in a loop. And there is an inner loop which processes each line in the file concerned. #inputFile is a variable which has the file name of the input... (2 Replies)
Discussion started by: akashtcs
2 Replies

9. Shell Programming and Scripting

sed script to remove nth characters from end of filename

Hi all, I have this basic script to remove, in this case 9 characters from the end of a file name. This is what I have so far, for file in *.mov do newname=`echo $file | sed 's/\(.*\)........./\1/' ` mv "$file" "$newname" done The problem is that it removes the file extension as well.... (2 Replies)
Discussion started by: Monkey Dean
2 Replies

10. Shell Programming and Scripting

writing shell script to find line of invalid characters

Hi, I have to write s script to check an input file for invalid characters. In this script I have to find the exact line of the invalid character. If the input file contain 2 invalid character sat line 10 and 17, the script will show the value 10 and 17. Any help is appreciated. (3 Replies)
Discussion started by: beginner82
3 Replies
Login or Register to Ask a Question