Replace character in files of entire folder? sed? or what?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace character in files of entire folder? sed? or what?
# 8  
Old 05-07-2013
Quote:
Originally Posted by rollinator
. . . but now I would like to limit the number of column to 41?
so how can I only output line 1 to 41 to the new outfile?
. . .
line or column? How about phrasing requests carefully?
# 9  
Old 05-07-2013
the sed works:

Code:
sed '42,$d' infile > outfile

but how to do this for all files in folder ... same question again?

---------- Post updated at 06:32 AM ---------- Previous update was at 06:31 AM ----------

Quote:
Originally Posted by RudiC
line or column? How about phrasing requests carefully?
line is what I desire... I was mixed up... sorry

Last edited by Scott; 05-07-2013 at 08:37 AM.. Reason: Code tags
# 10  
Old 05-07-2013
Code:
$ awk ' FNR <= 41 {gsub(",","."); print >FILENAME".out"}' *.dat

(untested)
# 11  
Old 05-07-2013
Code:
sed '42,$d' infile > outfile

Just a suggestion. The above is OK, but it is better in several says to just say head -n 41 infile > outfile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

Using sed command to replace "|" with ^ for all *.dat files in a folder not working

I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working. sed -i 's/"|"/\^/g' *.dat Is this the proper way to use sed command thank you very much for help. (3 Replies)
Discussion started by: cplusplus1
3 Replies

3. Shell Programming and Scripting

How to replace the first and last character which is pipe symbol in all files within a folder?

with in my files i have the data like this, starting with a pipe and ending the line with a pipe. all i want is to replace the first and last pipe , remove those trying to use following sed command, but it is only showing on the screen the entire data of the file as if it removed, but when i... (4 Replies)
Discussion started by: cplusplus1
4 Replies

4. Shell Programming and Scripting

Help with sed to replace entire line

Hi, I need to replace an entire mailx line as follows using sed: sed -e 's/<line1>/<newline>/g' <filename> But I am getting comman garbled error since the new line has many special characters. I enclosed allspecial chars in \ but still no use. Can any one help me? Please use code... (2 Replies)
Discussion started by: vinodhin4
2 Replies

5. Shell Programming and Scripting

Bash script read specific value from files of an entire folder

Hello, I heva a problem creating a script that read specifc value from all the files of an entire folder I have a number of email files into a directory and i need to extrect from each file 2 specific values. After that i have to put them into a new file that looks like that: To: value1 ... (1 Reply)
Discussion started by: ahmenty
1 Replies

6. UNIX for Dummies Questions & Answers

Removing ^M Character from all the files in a folder.

Hi Everyone, I am new and need your help. Can anyone please help me in removing the ^M character from all the file in a folder recursively. Please provide me the code. Response will be Really appreciated. Thanks in Advance (4 Replies)
Discussion started by: Manu_Learner
4 Replies

7. Shell Programming and Scripting

sed command to replace a character at last

Hi All, I have a file having one line only. It is like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|78|0037| I want to replace the numbers in last two columns by As. It should look like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|AA|AAAA| Please, suggest me any shell... (12 Replies)
Discussion started by: mukeshbaranwal
12 Replies

8. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

9. Shell Programming and Scripting

sed help,to replace the last character

cat input.txt agsbdafgd ertebrtreter ahrbrwerg The last character of a line that does not start with a would be changed to Z. Final output: agsbdafgd ertebrtreteZ ahrbrwerg Can anyone post the sed command to do that? (2 Replies)
Discussion started by: cola
2 Replies

10. Shell Programming and Scripting

Replace last 2 folder directory string with sed

Hi guys, I´m trying to replace the 2 last folders name in a list of directories with a new string, but I´m don´t know which regex to apply. Directories list: C/my user/documents/games & music C/my user/documents/photos 09-24-2008 C/my user/settings/config ?1_2 * The last folder may have... (11 Replies)
Discussion started by: cgkmal
11 Replies
Login or Register to Ask a Question