Sponsored Content
Top Forums Shell Programming and Scripting inserting a string to a text file Post 302318285 by goude on Thursday 21st of May 2009 08:38:26 AM
Old 05-21-2009
inserting a string to a text file

Hello

Can somebody please help me with the following script?
I'm trying to create a text file with 20 blank lines and then insert a string in line 2 but nothing is printed in the itxtfile. I can create the file with 20 blank lines but when I "tell" it to print something on the second line, it doesn't work.
Can somebody please tell me what am I doing wrong?

Thanks a lot

Code:
system ("touch /home/yanni/scripts/intxtfile"); 
my ($fileread, $filein, $fileout);
$filein = '/home/yanni/scripts/intxtfile';
$fileout = 'file.tmp';


open $fileread, '>', $filein || die ("Can't open: $filein $!");
print $fileread "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n"; 
close $fileread;

 open ($fileread, '<', $filein)  || die "Can't open: $filein $!";
 open ($filewrite,'>', $fileout) || die "Can't open: $fileout $!";
 
 while (<$fileread>) {
                      print $filewrite $_;
                      if ($.==2) { print $fileread "blablabla";}

                             }              

close ($fileread);
close ($filein);
close ($fileout);
rename ($fileout, $filein) || die "Unable to rename: $!";

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

inserting a String in the file(s)

Hi, I'm a newbee to Unix shell scripting. I want to write a shell script that inserts a new String(name&value pair) into a file(s) at a particular place.I willl have to write one script which when executed should insert a new variable in all the files in that particular directory. Say for eg:... (4 Replies)
Discussion started by: 2tbee
4 Replies

2. Shell Programming and Scripting

Inserting a String in a file header.

Dear all, I have a file created in the name sample.txt in UNIX with header and footer. How to insert a required string (for example "FILE1") in the header part after the file has been created. What kind of command can i use to do the same. Thanks in advance Hari (3 Replies)
Discussion started by: Hari123
3 Replies

3. Shell Programming and Scripting

inserting subscriber no in text file using KSH....

:confused:Dears , I have text file I need to insert the subscriber number at position 32, and need to keep the next field at position 53 (no increasing of the record lenght), I mean I just want to replace the spaces at position 32 with subscirber number . for example A B A ... (1 Reply)
Discussion started by: atiato
1 Replies

4. Shell Programming and Scripting

Inserting text and modifying the file

I am in a dire need of doing this job , please help from shell script or perl script. It will be highly appreciated. Please have a look at the following INPUT file; The first 14 rows are not of interest but I want them to be included in the output file as they are. From the row 14... (3 Replies)
Discussion started by: digipak
3 Replies

5. UNIX for Dummies Questions & Answers

Inserting a column into a text file

I have a tab delimited text file with multiple columns (data.txt). I would like to insert a column into the text file. The column I want to insert is in a text file (column.txt). I want to insert it into the 5th column of data.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

Inserting text into a new file

Hi all, I want to create a file and then insert some text into it. I'm trying to create a .sh script that will create a new python file from a template. Can someone tell me why this won't work, touch $1 | sed -e '1i\Some test code here' Sorry I'm quite new to all this! Just as a side... (3 Replies)
Discussion started by: ahodgson
3 Replies

7. Shell Programming and Scripting

Help with sed and inserting text from another file

I need to insert text from one file into another file after specific term. I guess sed is the best method of doing this and I can insert a specified text string using this script but I am not sure how to modify it to insert text from another file: #!/bin/sh sed 's/\<VirtualHost... (17 Replies)
Discussion started by: barrydocks
17 Replies

8. UNIX for Dummies Questions & Answers

Inserting text into a file with awk or sed

Hello, I've been trying to get a script working that fetches weather-data and converts it into an .ics file. The script works so far put I'm stuck at the point where I need to add specific static data. A thorough search through the forum did not point me into the right direction. #!/bin/bash... (3 Replies)
Discussion started by: Schubi
3 Replies

9. Shell Programming and Scripting

Inserting text in file names while copying them.

I'm trying to find a Bourne shell script that will copy files from one directory using a wild card for the file name (*) and add some more characters in the middle of the file name as it is copied. As an example: /u01/tmp-file1.xml => /u02/tmp-file1-20130620.xml /u01/tmp-file2.xml => ... (6 Replies)
Discussion started by: Tony Keller
6 Replies

10. UNIX for Dummies Questions & Answers

Inserting information from old text file into a new text file

Hello, I'm trying to take information from a list of hundreds of subject ids (where each line is a new subject id), and insert each line into a new text file that contains the pathnames for each subject. To clarify, all subject have a similiar path name (e.g., C:\data\SUBJECT_ID\) that contains... (4 Replies)
Discussion started by: invisibledwarf
4 Replies
VMOD_STD(3)															       VMOD_STD(3)

NAME
vmod_std - Varnish Standard Module SYNOPSIS
import std DESCRIPTION
The Varnish standard module contains useful, generic function that don't quite fit in the VCL core, but are still considered very useful to a broad audience. FUNCTIONS
toupper Prototype toupper(STRING S) Return value String Description Converts the STRING S to upper case. Example set beresp.http.x-scream = std.toupper("yes!"); tolower Prototype tolower(STRING S) Return value String Description Converts the STRING to lower case. Example set beresp.http.x-nice = std.tolower("VerY"); set_up_tos Prototype set_ip_tos(INT I) Return value Void Description Sets the Type-of-Service flag for the current session. Please note that the TOS flag is not removed by the end of the request so probably want to set it on every request should you utilize it. Example if (req.url ~ ^/slow/) { std.set_up_tos(0x0); } random Prototype random(REAL a, REAL b) Return value Real Description Returns a random REAL number between a and b. Example set beresp.http.x-random-number = std.random(1, 100); log Prototype log(STRING string) Return value Void Description Logs string to the shared memory log. Example std.log("Something fishy is going on with the vhost " + req.host); syslog Prototype syslog(INT priority, STRING string) Return value Void Description Logs string to syslog marked with priority. Example std.syslog( LOG_USER|LOG_ALERT, "There is serious troble"); fileread Prototype fileread(STRING filename) Return value String Description Reads a file and returns a string with the content. Please note that it is not recommended to send variables to this function the caching in the function doesn't take this into account. Also, files are not re-read. Example set beresp.http.x-served-by = std.fileread("/etc/hostname"); duration Prototype duration(STRING s, DURATION fallback) Return value Duration Description Converts the string s to seconds. s can be quantified with the usual s (seconds), m (minutes), h (hours), d (days) and w (weeks) units. If it fails to parse the string fallback will be used Example set beresp.ttl = std.duration("1w", 3600); integer Prototype integer(STRING s, INT fallback) Return value Int Description Converts the string s to an integer. If it fails to parse the string fallback will be used Example if (std.integer(beresp.http.x-foo, 0) > 5) { } collect Prototype collect(HEADER header) Return value Void Description Collapses the header, joining the headers into one. Example std.collect(req.http.cookie); This will collapse several Cookie: headers into one, long cookie header. SEE ALSO
o vcl(7) o varnishd(1) HISTORY
The Varnish standard module was released along with Varnish Cache 3.0. This manual page was written by Per Buer with help from Martin Blix Grydeland. COPYRIGHT
This document is licensed under the same licence as Varnish itself. See LICENCE for details. o Copyright (c) 2011 Varnish Software AUTHOR
Per Buer 1.0 2011-05-19 VMOD_STD(3)
All times are GMT -4. The time now is 10:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy