Making Changes without opening file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making Changes without opening file
# 1  
Old 03-13-2006
Making Changes without opening file

Hello,

I'm new to scripting, I have a file test.dat. I want to make changes to it with out openning it.

Example: test.dat has rows, and I want to change value "LA" to "TX" without opening it or without writing it to another file.

Is it possible?

Thanks
# 2  
Old 03-14-2006
perl -pi -e "s/LA/TX/g;" test.dat

Cheers
ZB
# 3  
Old 03-14-2006
Try this one sed 's/LA/TX/g' filename > filename1
# 4  
Old 03-14-2006
Quote:
Originally Posted by dhana_1979
Try this one sed 's/LA/TX/g' filename > filename1
request was not to write to another file,
your command redirects to filename1
in such a case you need to use the -i option available in GNU sed
# 5  
Old 03-14-2006
Code:
(echo 'g/LA/TX/g'; echo 'wq') | ex -s filename

# 6  
Old 03-15-2006
Code:
ruby -i -pe 'gsub(/LA/,"TX")' test.dat

Smilie
# 7  
Old 03-15-2006
Quote:
awk '{gsub("LA","TX"); print}' filename
I asked the same question last time ^O^. Its the easiest way to solve ur problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to read a file without opening the file and delete last line?

I have file called "text". The contents are as below : aaa bbb ccc ddd eee ffff ddd hhhh iiii I want to read this file without opening and and delete the last line. How can it be done? (4 Replies)
Discussion started by: the_hunter
4 Replies

2. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

3. Shell Programming and Scripting

Query about opening the file

I have a query regard the opening of the file. Suppose I have opened the file Let's say view filename And then I found that I have to do some changes in that, but I do not want to close the file Then how I can change the permission of the file from read mode to write mode Regards Adi (6 Replies)
Discussion started by: adisky123
6 Replies

4. Shell Programming and Scripting

Xmllint - Xml-file problem --ods file not opening

Dear All, this is my first post on this Forum, glad to be here. I'm trying to fix an .ods file. Yes, I had a backup, but it's also corrupted. When opening the document I get this EM: read error format error discovered in the file in sub-document content.xml at 2,337040(row,col). So I... (3 Replies)
Discussion started by: jameslast
3 Replies

5. Shell Programming and Scripting

Problems with file opening

Hi All, I have a file test.dat. When I view this file using code1 , that time no problem. But when I open this file using code2, that time some lines are missing. I don't know why is the problem occurred. I already convert dos2unix fromat. But problem is not solving. Please help me about the... (3 Replies)
Discussion started by: mnmonu
3 Replies

6. Shell Programming and Scripting

Deleting lines inside a file without opening the file

Hi, Just consider there are around 10 lines in a file. Now is it possible to delete the first 2 lines in the file without opening the file. No matter whatever the content of the file is, I just wanna delete the first 2 lines without opening the file. Is that possible? If so, please help me out.... (3 Replies)
Discussion started by: toms
3 Replies

7. Shell Programming and Scripting

how to know whether that file has eol or noeol before opening that file in VI editor

Hi, I want to check whether file has EOL or NOEOL before opening this file in VI editor. My file is very big its in terms of 15-20 MB. I am using ksh for this. When we opened the file in vi editor, normally at last line we are able to see whether this is eol or noeol file. But i does want... (1 Reply)
Discussion started by: HariRaju
1 Replies

8. Shell Programming and Scripting

making change in file without opening it

hi everyone i have script name cs-700kl looking like this mv klk_ta_01780_023 klk_ta_01780_023_m tr "" "" <klk_ta_01780_023_m> klk_ta_01780_023 i'm running it in sh cs-700kl i want every time that he will take the value of the end of the file in this example klk_ta_01780_023 the value... (0 Replies)
Discussion started by: naamas03
0 Replies

9. UNIX for Dummies Questions & Answers

delete file without opening vi

hi there guys, wonder if any gurus can help me out on this one... try searching the past threads but cant find anything. i have this huge file but when i use vi to open it it gives me the following error: <"pmrepserver.txt""/var/tmp/Ex86200" There is not enough space in the file... (7 Replies)
Discussion started by: lweegp
7 Replies

10. UNIX for Dummies Questions & Answers

opening a file

im trying to open a file in my bin directory and the farthest i can get is into the folder but not the actual file itself i use text edit as the editor. when i try to open the file it says it doesn't exist here is what i type cd bin open cmnds (dir. which it is under) open test no such... (4 Replies)
Discussion started by: hiei
4 Replies
Login or Register to Ask a Question