Sed,nawk for inputfile and out put file same


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed,nawk for inputfile and out put file same
# 1  
Old 04-09-2008
Sed,nawk for inputfile and out put file same

Hi,

I am using sed and nawk command for replace/add/remove on file records.

But when I am using the inputfile name and directing output to the same inpu name file becomes empty.
I don't want to use to copy it to another file and move it back to original file.

Example:

sed 's/./,&/17' inputfile > inputfile--------->becomes inputfile empty

I want it to be work in a sigle comamnd can it be possible, please let me know.
# 2  
Old 04-09-2008
Quote:
Originally Posted by svenkatareddy
I don't want to use to copy it to another file and move it back to original file.
You don't have any choice if your sed version doesn't support the -i option.

Regards
# 3  
Old 04-09-2008
here's the poor-man's version of 'sed -i':
Code:
{ rm FILE; sed -e '...' > FILE; } < FILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK Variable instead inputfile

Hi , can I use var1 instead of inputfile (index.html) in AWK? var1='<script>text1 asd asd asd</script> text2 asd, asd text3 asd asd asd asd text4 asdasdasd asd asd' awk '/<script /{p=1} /<\/script>/{p=0; next}!p' index.html Thank you! (7 Replies)
Discussion started by: sanantonio7777
7 Replies

2. Shell Programming and Scripting

Need help parsing data with sed and/or nawk

Good day all. I have the following entries of data in a file in a column, however, I need this data written on a single line with several parameters in a different order. Current format: Treatment ,parmeter1=value ,parmeter2=value ,parmeter3=value ,parmeter4=value... (7 Replies)
Discussion started by: BRH
7 Replies

3. Shell Programming and Scripting

Sed/Nawk help

Hi all, I have the following piece of code which reformats a file but the part that isn't working converts a date from dd mmm ccyy format to 2 fields containing dd/mm/ccyy,ccyy-mm-dd hh:mm:ss.000000 This is for a DB2 load file. The problem I have is that the input dd values (the dd variable... (2 Replies)
Discussion started by: dazedandconfuse
2 Replies

4. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

5. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

How to put for loop in nawk

Hello All, How i can put loop in nawk. what i want is that i define a variable which contain vlaues like var='1 2 3 4 5' and then define for loop which gives vlaue to nawk one by one to varilable inside nawk and then print it. cat /omp-data/logs/5etr/081121.APX | nawk -v CDNLIST='700 701' ' ... (1 Reply)
Discussion started by: wakhan
1 Replies

7. Shell Programming and Scripting

Need help in sed or nawk replace RE

Dear Friends, I am trying to replace the following pattern , But I cant understand how to express the RE in this case . Please help me with a sed command to replace . (Address = 918h : Initial = 0000h : RD /WR (Address = 91Ah : Initial =... (2 Replies)
Discussion started by: user_prady
2 Replies

8. Shell Programming and Scripting

awk,nawk,sed, delimiter |~|

RECORD=NEW|~|VENDORN=LUCENT|~|VENDORM=CBX500_REAR|~|NETWORK=ATM|~|SUBNETWORK=N/A|~|SITE=CIL|~|REGION=KN|~|COUNTRY=PS|~|SWITCH=SWITCH1|~|E THERNET=N/A|~|LOOPBACK=N/A|~|SHELF=N/A|~|SLOT=14|~|SUBSLOT=N/A|~|STSCHAN=N/A|~|PORT=S14|~|DS1SLOT=N/A|~|LINE=N/A|~|LPORTID=N/A|~|CARDDESC=N/A|~|CARDTYPE=BAC2RT0... (7 Replies)
Discussion started by: knijjar
7 Replies

9. Shell Programming and Scripting

put each word in new line - sed or tr

Hello ! I have a result of ls command in a file: file1 file2 file3.out file4.pdf file5 they all are separated by space. I need to put them on a separate line example: file1 file2 file3.out file4.pdf fil35 i tried sed 's/ /\n/g' inputfile > outputfile but did not help (3 Replies)
Discussion started by: hemangjani
3 Replies

10. Shell Programming and Scripting

Inputfile for shell-script

I want to use an inputfile for a shell-script Inputfile consists 10 lines In the script variables have to be filled with these lines $1 must be line 1 $2 must be line 2 and so on How do I get this done ??? :confused: :confused: (2 Replies)
Discussion started by: cns
2 Replies
Login or Register to Ask a Question